Question

I am using Spring 3.2 with Java based configuration and have some problems with my unit tests (JUnit 4.8.1). So this is a test runner:

 @RunWith(SpringJUnit4ClassRunner.class)
 @ContextConfiguration(classes={TestConfig.class})
 public class ManualTest
 {
     @Autowired
     ...

Howeever, I am receiving this error:

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)

As the Spring blog states, Spring 3.2 is inlining CGLIB 3. So why do I receive this error?

I am using Gradle 1.3 as build management tool and STS as IDE. When calling gradle eclipse gradle pulls in the dependencies twice: one time as plain jar and one time as library:

First as plain jar: plain jar

and than as library:

library

In the plain jar section I had still Spring 3.1 configured, while in the library section there was Spring 3.2. So I removed the plain jars and everything was working.

This is my project 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/"
        }
    }
}

And the build.gradle from the master project

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
    {
    }
}
Was it helpful?

Solution

I deleted all Eclipse projects and settings and all Gradle temporary files. Then I tried to import the project in Eclipse (Import Gradle project..). This failed with an exception. Then I deleted the Gradle settings within the Eclipse project and after that the import worked.

So I will not use gradle eclipse with version 1.3.

Also the additional source set path did not make its way into the Eclipse project as source path.

OTHER TIPS

I had the same issue. Just add this dependency to your pom.xml file:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>

And your unit tests and runtime code should work properly without cglib errors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top