CGLIB is required to process @Configuration classes

問題
使用 Spring3 @Configuration 創建一個應用程式配置檔,如下圖所示:
import org.springframework.context.annotation.Configuration;

@Configuration
public class AppConfig {

	@Bean
   //...

}
但是,運行時,它會出現以下錯誤資訊:
org.springframework.context.support.AbstractApplicationContext prepareRefresh
//...
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 com.zaixian.core.App.main(App.java:12)

解決

要在 Spring3中 使用 @Configuration,需要手動包含CGLIB庫,只是聲明它的 Maven pom.xml 檔。
<dependency>
		<groupId>cglib</groupId>
		<artifactId>cglib</artifactId>
		<version>2.2.2</version>
	</dependency>


上一篇: Spring依賴注入servlet會話監聽器 下一篇: Spring初學快速入門