CGLIB is required to process @Configuration classes. Either add CGLIB to the classpath or remove...

问题

使用 Spring3 @Configuration 创建一个应用程序配置文件,如下图所示:


    /**  
     * @Title: ConfigAnnotation.java
     * @Package com.acconsys.ids.config
     * @Description: TODO(用一句话描述该文件做什么)
     * @author 35725
     * @date 2019年12月28日 下午4:05:36 
     * @version V1.0  
     */
    
package com.acconsys.ids.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
     * @ClassName: ConfigAnnotation
     * @Description: TODO(这里用一句话描述这个类的作用)
     * @author 35725
     * @date 2019年12月28日
     *
     */

@Configuration
@ComponentScan("com.acconsys.ids.config")
public class ConfigAnnotation {
	
	

}

但是,运行时,它会出现以下错误信息:

 INFO [main] - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
 INFO [main] - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
 INFO [main] - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@863941: startup date [Sat Dec 28 17:14:17 CST 2019]; root of context hierarchy
 INFO [main] - JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
 INFO [main] - JSR-330 'javax.inject.Named' annotation found and supported for component scanning
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: [configAnnotation]
	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:686)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:625)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
	at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:73)
	at com.acconsys.ids.IdsApplication.main(IdsApplication.java:42)

解决

要在 Spring3中 使用 @Configuration,需要手动包含CGLIB库,只是声明它的 Maven pom.xml 文件。

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章