CGLIB需要处理@Configuration类

时间:2013-08-14 06:09:37

标签: 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

我有以下代码,

@Configuration
public class AppConfig {

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

当我运行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)

为了解决这个问题,如果我添加cglib-2.1.jar,我将获得以下异常......

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

为了解决这个问题,如果我添加asm3.1.jar,我就会遇到异常。

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

如何克服我的初始异常 - CGLIB is required to process @Configuration classes ?

4 个答案:

答案 0 :(得分:12)

  

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

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

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

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

答案 1 :(得分: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的信息作为我。

答案 2 :(得分:2)

您的计划中需要CGLIB库。 您可以使用Maven下载依赖项。

由xry发布,由gerrytan发布。

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

如果您不使用maven(或其他依赖工具),可以从CGLIB HomePage下载该库。

答案 3 :(得分:1)

使用cglib-2.2.jar和asm-3.3.jar并将其添加到类路径中

相关问题