14

Am using Spring 3.1. War is not built using Maven. Its just a normal build. I have below jars in my class path.

antlr-runtime-3.0.1.jar
commons-logging-1.1.1.jar
org.apache.commons.logging.jar
org.springframework.aop-3.1.0.M2.jar
org.springframework.asm-3.1.0.M2.jar
org.springframework.aspects-3.1.0.M2.jar
org.springframework.beans-3.1.0.M2.jar
org.springframework.context-3.1.0.M2.jar
org.springframework.context.support-3.1.0.M2.jar
org.springframework.core-3.1.0.M2.jar
org.springframework.core-3.1.0.RELEASE.jar
org.springframework.core.jar
org.springframework.expression-3.1.0.M2.jar
spring-beans-3.0.5.RELEASE.jar
spring-context-3.0.5.RELEASE.jar

I have below code,

@Configuration
public class AppConfig {

    @Bean(name="helloBean")
    public HelloWorld helloWorld()
    {
        return new HelloWorldImpl();
    }
}

When I run main method, am getting below exception

Exception in thread "main" java.lang.IllegalStateException: CGLIB is required to process @Configuration classes. Either add CGLIB to the classpath or remove the following @Configuration bean definitions: [appConfig]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:297)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigurationClasses(ConfigurationClassPostProcessor.java:200)

To overcome this, if I add cglib-2.1.jar, am getting below exception..

java.lang.ClassNotFoundException: org.objectweb.asm.Type

To overcome this, if I add asm3.1.jar, am getting below exception.

java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.

How can I overcome my initial exception - CGLIB is required to process @Configuration classes ?

1

4 Answers 4

14

War is not built using Maven. Its just a normal build

Your problem exactly highlights why you should use Maven (or other similar dependency tool) -- congratulation on learning things the hard way. Libraries in Java world often have a very complex dependency tree and Maven can help resolve it all for you.

In your case, had you used maven you just need to include cglib dependency and all its transitive dependency (including asm) will be resolved for you

<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>3.0</version>
</dependency>
3
  • Thanks..But, is it not possible to solve this without switching to Maven? Few URLs are blocked by my company and when I tried building using Maven, there was a connection timeout.. Aug 14, 2013 at 7:50
  • The other way to solve this is you have to manually resolve all transitive dependency of cglib (and all other 3rd party libraries you decide to use) and include it to your classpath. Maven central repository search engine: search.maven.org can help you -- from there you can lookup what are dependencies of a particular artifact. Please note maven is a widely used infrastructure in a corporate environment. Larger corporate often have its own mirror of central repository (see Nexus). I strongly suggest you persuade your network admin to enable Maven
    – gerrytan
    Aug 14, 2013 at 11:38
  • It should be independent to work without using Maven. Maven should not be a requirement. Jan 15, 2017 at 17:49
5

Starting with Spring 3.2, it is no longer necessary to add cglib as an explicit dependency.

Reference: http://www.baeldung.com/2011/10/20/bootstraping-a-web-application-with-spring-3-1-and-java-based-configuration-part-1/#cglib_gone

This answer for those who wondered why their project running normally without cglib, and come to this page searching for info about cglib as me.

2

CGLIB library is required in your program. You can use Maven to download the dependency.

by xml as posted by gerrytan ie.

<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.0</version>
</dependency>

If you are not using maven (or other dependency tool), you can download the library from CGLIB HomePage.

1

Use cglib-2.2.jar and asm-3.3.jar and add it your classpath

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.