Spring Framework中的基于Java的Java配置不起作用

And*_*ili 2 java spring spring-mvc spring-annotations

我正在阅读有关基于Spring Java的配置的这篇文章.我正在创建一个类似于本教程中的示例,但我正在使用Maven进行构建过程.

我已经添加了以下依存关系到我的项目:spring-core,spring-bean,spring-context,spring-context-support和spring-asm.

问题是,当我尝试执行我的应用程序时,我收到以下错误消息:

feb 13, 2013 10:26:49 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4ba4536d: startup date [Wed Feb 13 10:26:49 CET 2013]; root of context hierarchy
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: [helloWorldConfig]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:327)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:222)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:681)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:620)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:446)
    at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:73)
    at org.andrea.myexample.myJavaConfiguration.MainApp.main(MainApp.java:13)
Run Code Online (Sandbox Code Playgroud)

在线阅读我已经明白要使用这些注释(@Configuration和@Bean)我必须将spring-asm依赖项添加到我的项目中.我试过但它没有用.

这是我的整个pom.xml文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.andrea.myexample</groupId>
<artifactId>myJavaConfiguration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>myJavaConfiguration</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>3.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>3.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-asm</artifactId>
        <version>3.1.1.RELEASE</version>
    </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

有人能帮我吗?

Xav*_*ica 6

在同一个教程页面中,它声明您需要在类路径中包含CGLib jar(强调添加):

让我们使用Eclipse IDE并按照以下步骤创建Spring应用程序:

...
3 - 因为您使用的是基于Java的注释,所以您还需要从Java安装目录和ASM.jar库中添加CGLIB.jar,该库可以从asm.ow2.org下载.
...

使用Maven,您需要将以下依赖项添加到您的pom.xml:

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

资源