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.yiibai.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>