Tôi đang sử dụng Spring 3.2 với cấu hình dựa trên Java và có một số vấn đề với các bài kiểm tra đơn vị của tôi (JUnit 4.8.1). Vì vậy, đây là một Á hậu kiểm tra:Thử nghiệm đơn vị mùa xuân 3.2 với cấu hình dựa trên Java
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes={TestConfig.class})
public class ManualTest
{
@Autowired
...
Howeever, tôi nhận được lỗi này:
Caused by: java.lang.IllegalStateException: CGLIB is required to process @Configuration classes. Either add CGLIB to the classpath or remove the following @Configuration bean definitions: [testConfig]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:327)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:222)
Khi Spring blog tiểu bang, mùa xuân 3.2 là nội tuyến cglib 3. Vậy tại sao tôi nhận được lỗi này?
Tôi đang sử dụng Gradle 1.3 làm công cụ quản lý xây dựng và STS làm IDE. Khi gọi gradle eclipse
gradle kéo trong sự phụ thuộc hai lần: một lần như jar đồng bằng và một lần như thư viện:
Đầu tiên là jar đồng bằng:
và hơn như thư viện:
Trong phần jar bình thường, tôi vẫn còn cấu hình Spring 3.1, trong khi trong phần thư viện có Spring 3.2. Vì vậy, tôi loại bỏ các lọ bình thường và tất cả mọi thứ đã được làm việc.
Đây là dự án của tôi build.gradle
configurations
{
driver
}
dependencies
{
driver 'com.oracle:ojdbc6:11.2.0'
compile "org.springframework:spring-jdbc:$springVersion"
testCompile 'com.oracle:ojdbc6:11.2.0'
testCompile "org.springframework:spring-test:$springVersion"
testCompile "commons-dbcp:commons-dbcp:$dbcpVersion"
testCompile "junit:junit:$junitVersion"
testCompile "org.slf4j:slf4j-log4j12:$slf4jVersion"
}
sourceSets
{
main
{
java
{
srcDirs 'src/main/java', "$buildDir/generated-sources/"
}
}
}
Và build.gradle từ dự án tổng thể
configure(allprojects)
{
ext.dbcpVersion = '1.4'
ext.springVersion = '3.2.0.RELEASE'
ext.junitVersion = '4.8.1'
ext.slf4jVersion = '1.7.2'
}
subprojects
{
// Artifact settings
group = 'xxx'
version = '1.0-SNAPSHOT'
// Standard plugins
apply plugin: 'java'
apply plugin: 'eclipse'
// Repositories
repositories
{
mavenLocal()
maven
{
url "http://repo.springsource.org/release"
}
mavenCentral()
}
// Standard dependencies
dependencies
{
}
}
Bạn có thể đăng nội dung classpath của mình không? hoặc pom.xml nếu sử dụng maven? – ElderMael
Không thành công trong cả Eclipse và trên dòng lệnh gradle? – artbristol
Chỉ trong Eclipse (STS). – ChrLipp