解决升级 Spring Boot 2.6后,因循环引用导致启动时报错 BeanCurrentlyInCreationException 的问题

SpringBoot2.6默认禁止了循环引用,导致启动时出现异常。可以通过设置`spring.main.allow-circular-references=true`来允许。此外,SpringMVC的请求路径匹配策略改为PathPatternParser。详细变更可查阅官方文档。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

升级 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值