这里是weihubeats,觉得文章不错可以关注公众号小奏技术,文章首发。拒绝营销号,拒绝标题党
背景
Spring Boot 版本由2.4.2
升级到2.6.8
,然后启动发现PageHelper
报错
错误信息
pagehelper-spring-boot-starter
版本:1.3.0
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
13.060 ERROR o.s.b.d.LoggingFailureAnalysisReporter:40 restartedMain
***************************
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 0
解决
看错误消息很明显就是出现了循环依赖,然后发现Spring Boot
2.6以上的版本默认是禁用循环依赖的。所以解决方式有两种
- 开启循环依赖
spring.main.allow-circular-references = true
这种方式不推荐,毕竟都禁用了循环依赖,所以就是不推荐循环依赖。我们代码也不应该出现循环依赖
- 升级
pagehelper-spring-boot-starter
版本
可以看到pagehelper-spring-boot-starter
官方新版本是解决了这个bug的,所以我们升级 pagehelper-spring-boot-starter
到最新版本就行了