Relying upon circular references is discouraged and they are prohibited by default.循环依赖bug解决

文章讲述了在SpringBoot2.6及以上版本中,使用PageHelper时遇到的Bean循环依赖问题,提供了三种解决方案:开启允许循环引用、更新PageHelper版本至1.4.1以及降级SpringBoot版本。作者选择了更新PageHelper版本的方案并成功解决问题。

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

问题

springboot2.6版本以上,在使用pageHelper时运行boot项目提示报错

***************************
APPLICATION FAILED TO START
***************************

Description:

The dependencies of some of the beans in the application context form a cycle:

┌──->──┐
|  com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration
└──<-──┘


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.


Process finished with exit code 1

原因

目前的bean在被创建的同时,已经在被引用了!也可以理解为在被引用的同时,又在创建!致使这个Bean是无法被使用的,因此出现:“循环依赖”的情况

第一种解决方式

SprinBoot 2.6以后的版本默认不允许循环依赖,但作为最后的手段,可以通过将spring.main.allow-circular-references 设置为 true来自动中断循环。在application.properties中添加就行

第二种解决方式(我选择的方式)

调整pageHelper版本,官方进行了修复

我项目最开始的版本是:

	<dependency>
			<groupId>com.github.pagehelper</groupId>
			<artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
			<version>1.2.12</version>
		</dependency>

将其调整为:

<dependency>
			<groupId>com.github.pagehelper</groupId>
			<artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
			<version>1.4.1</version>
		</dependency>

第三种解决方式

降低SpringBoot版本,改为2.5及其以下

个人选择第二种。最后结果能正常启动。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值