升级 Spring Boot 2.6 后,有些人在通过 main() 方法启动应用时,也可能遇到以下异常:
比如如下情况:
@Component
public class A {
@Autowired
protected B b;
}
@Component
public class B {
@Autowired
protected A a;
}
就出出现上述问题。
这是因为从 2.6 开始,Spring Boot 默认禁用了如此的循环引用。如要解决,可以在application.properties配置中如下设置:
spring.main.allow-circular-references=true
Spring Boot 2.6 还将 Spring MVC 默认的请求路径匹配策略从 AntPathMatcher
变更为了PathPatternParser
。
你可以访问官方文档查看更多变更详情:Spring Boot 2.6 Release Notes · spring-projects/spring-boot Wiki · GitHub