问题
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及其以下
个人选择第二种。最后结果能正常启动。