【发布时间】:2020-11-07 18:58:58
【问题描述】:
SportConfig.java
package luv2code;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SportConfig {
// define bean for our sad fortune service
@Bean
public Fortune sadfortuneService() {
return new SadFortuneService();
}
// define bean for our swim coach AND inject dependency
@Bean
public Coach swimCoach() {
return new SwimCoach(sadfortuneService());
}
}
当我运行 main 方法时,出现以下异常:
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: [sportConfig]
at org.springframework.context.annotation.ConfigurationClassPostProcessor.enhanceConfigurationClasses(ConfigurationClassPostProcessor.java:214)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanFactory(ConfigurationClassPostProcessor.java:145)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:640)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:405)
at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:65)
at luv2code.JavaConfiguartionDemoApp.main(JavaConfiguartionDemoApp.java:9)
【问题讨论】:
-
错误信息从字面上解释了解决问题应该采取的措施...
-
请发布您的构建脚本
-
在创建 'swimCoach' 作为方法参数时,你能自动装配 'sadfortuneService' bean 吗?
标签: java spring spring-boot