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>

 

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