CGLIB需要处理@Configuration类

use*_*578 13 spring

使用Spring 3.1.战争不是使用Maven构建的.它只是一个正常的构建.我的班级路径中有以下的罐子.

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
Run Code Online (Sandbox Code Playgroud)

我有以下代码,

@Configuration
public class AppConfig {

    @Bean(name="helloBean")
    public HelloWorld helloWorld()
    {
        return new HelloWorldImpl();
    }
}
Run Code Online (Sandbox Code Playgroud)

当我运行main方法时,我遇到异常

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)
Run Code Online (Sandbox Code Playgroud)

为了解决这个问题,如果我补充一下cglib-2.1.jar,我会得到以下异常..

java.lang.ClassNotFoundException: org.objectweb.asm.Type
Run Code Online (Sandbox Code Playgroud)

为了克服这个问题,如果我补充一下asm3.1.jar,我就会遇到异常.

java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.
Run Code Online (Sandbox Code Playgroud)

我怎样才能克服我的初始异常 - CGLIB is required to process @Configuration classes ?

ger*_*tan 13

战争不是使用Maven构建的.它只是一个正常的构建

你的问题正好突出了为什么你应该使用Maven(或其他类似的依赖工具) - 祝贺学习困难的方法.Java世界中的库通常具有非常复杂的依赖树,Maven可以帮助您解决所有问题.

在你的情况下,如果你使用maven,你只需要包含cglib依赖项,它的所有传递依赖(包括asm)都将为你解决

<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>3.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)


Erl*_*lan 5

与Spring 3.2开始,就不再需要添加CGLIB作为一项明确的依赖性.

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

对于那些想知道为什么他们的项目在没有cglib的情况下正常运行的人来说,这个答案,并来到这个页面搜索有关cglib的信息作为我.