The Spring container is able to resolve Setter-based circular dependencies but gives a runtime exception BeanCurrentlyInCreationException in case of Constructor-based circular dependencies. In case of Setter-based circular dependency, the IOC container handles it differently from a typical scenario wherein it would fully configure the collaborating bean before injecting it. For eg., if Bean A has a dependency on Bean B and Bean B on Bean C, the container fully initializes C before injecting it to B and once B is fully initialized it is injected to A. But in case of circular dependency, one of the beans is injected to the other before it is fully initialized.
spring 循环依赖 form stackoverflow
最新推荐文章于 2024-07-31 15:04:39 发布
本文探讨了Spring容器在处理setter和构造器依赖循环中的不同行为,并提供了设计建议和处理策略。重点介绍了如何避免设计循环依赖,以及在必要时使用setter注入或其他方式来管理初始化和注入。
173万+

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



