痛快!SpringBoot终于禁掉了循环依赖!
Java后端技术
共 2122字,需浏览 5分钟
·
2022-06-10 20:14
往期热门文章:
验证代码小片段
@Component
@RequiredArgsConstructor
public class CircularDependencyA {
private final CircularDependencyB circB;
}
@Component
@RequiredArgsConstructor
public class CircularDependencyB {
private final CircularDependencyA circA;
}
The dependencies of some of the beans in the application context form a cycle:
┌─────┐
| circularDependencyA defined in file [cir/CircularDependencyA.class]
↑ ↓
| circularDependencyB defined in file [cir/CircularDependencyB.class]
└─────┘
Action:
Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.
spring.main.allow-circular-references=true
做对的事
AbstractAutowireCapableBeanFactory#allowCircularReferences
/** Whether to automatically try to resolve circular references between beans. */
private boolean allowCircularReferences = true;
往期热门文章:
2、超越 Xshell!号称下一代 Terminal 终端神器,用完爱不释手!
8、我怀疑这是 IDEA 的 BUG,但是我翻遍全网没找到证据!
9、Spring MVC 中的 Controller 是线程安全的吗?
10、Gitee 倒下了???
评论