内容目录
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'xxxService': Requested bean is currently in creation: Is there an unresolvable circular reference?
升级 Spring Boot 2.6 后,在 Tomcat 中启动有可能出现以上异常。
有些人在通过 main() 方法启动应用时,也可能遇到以下异常:
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 settingspring.main.allow-circular-references
totrue
.
以上异常,都可以通过在配置文件中配置如下属性以恢复正常。
spring.main.allow-circular-references=true
这是因为从 2.6 开始,Spring Boot 默认禁用了类似如下的循环引用:
@Component
public class A {
@Autowired
protected B b;
}
@Component
public class B {
@Autowired
protected A a;
}
Spring Boot 2.6 还将 Spring MVC 默认的请求路径匹配策略从 AntPathMatcher
变更为了PathPatternParser
。
你可以访问官方文档查看更多变更详情:https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.6-Release-Notes
0 条评论
撰写评论