14

我正在使用 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

4 回答 4

14

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

您的问题恰恰突出了为什么您应该使用 Maven(或其他类似的依赖工具) - 祝贺您以艰难的方式学习事物。Java 世界中的库通常具有非常复杂的依赖关系树,Maven 可以帮助您解决这一切。

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

<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib</artifactId>
    <version>3.0</version>
</dependency>
于 2013-08-14T06:58:46.860 回答
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 的信息。

于 2015-09-09T09:25:34.527 回答
2

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

由 gerrytan ie 发布的 xml。

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

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

于 2014-01-05T04:42:23.267 回答
1

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

于 2014-11-17T13:40:31.950 回答