案发现场
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
┌─────┐
| asyncConfig defined in file [E:\code\spring-boot-demo\target\classes\com\itplh\config\AsyncConfig.class]
└─────┘
原因分析
@Configuration
public class AsyncConfig {
private AsyncConfig asyncConfig;
public AsyncConfig(AsyncConfig asyncConfig) {
this.asyncConfig = asyncConfig;
}
}
用了构造器注入当前类,导致循环依赖
解决方案
使用 set注入
@Configuration
public class AsyncConfig {
@Autowired
private AsyncConfig asyncConfig;
}
本文详细解析了Spring Boot中因构造器注入同一类实例导致的循环依赖问题,并提供了使用set注入作为解决方案的具体代码示例。
3459

被折叠的 条评论
为什么被折叠?



