Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.6k views
in Technique[技术] by (71.8m points)

spring - CGLIB is required to process @Configuration classes

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...