赞
踩
升级spring-boot到最新版本,sping报如下错误,pageHelper插件的类
PageHelperAutoConfiguration存在自身循环依赖?为什么spring-boot旧版本没有报?一时间脑子里出现这两个问题。
spring容器本身通过三级缓存处理了循环依赖,为什么升级了spring-boot这个问题就暴露了?猜测处理循环依赖存在开关.
原来新版本springboot在初始化的时候,设置了是否允许循环依赖 ,boolean的默认值为false
关于spring如何根据这个参数以及三级缓存处理循环依赖,后面单看一篇详细说明。
pageHelper自身循环依赖已经实锤了,因为springboot禁止了循环依赖,那让springboot允许循环依赖不就可以了吗!
spring.main.allow-circular-references=true 启动项目,成功了!问题解决!但是这样感觉是不是太没劲了,PageHelperAutoConfiguration的循环依赖问题没有找到。
那我们就来看看PageHelperAutoConfiguration为什么产生了循环依赖。同样是先观察分析!
info日志看不出问题,我们先加上debug日志 :debug=true
果然加上debug日志,输出丰富多了,日志可以是问题的初略定位,很多问题都能从日志看出端倪! 分析这一堆日志,会发现有两行明显格格不入,他们不是出自spring代码,看看这两行代码干了什么!
- @Configuration
- @ConditionalOnBean(SqlSessionFactory.class)
- @EnableConfigurationProperties(PageHelperProperties.class)
- @AutoConfigureAfter(MybatisAutoConfiguration.class)
- public class PageHelperAutoConfiguration {
- @Autowired
- private List<SqlSessionFactory> sqlSessionFactoryList;
-
- @Autowired
- private PageHelperProperties properties;
-
- @Bean
- @ConfigurationProperties(prefix = PageHelperProperties.PAGEHELPER_PREFIX)
- public Properties pageHelperProperties() {
- return new Properties();
- }
-
- @PostConstruct
- public void addPageInterceptor() {
- PageInterceptor interceptor = new PageInterceptor();
- Properties properties = new Properties();
- //问题出在这行所引用的方法
- properties.putAll(pageHelperProperties());
- properties.putAll(this.properties.getProperties());
- interceptor.setProperties(properties);
- for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList) {
- sqlSessionFactory.getConfiguration().addInterceptor(interceptor);
- }
- }
- }

这是PageHelperAutoConfiguration的代码,@PostConstruct是注入完成后、初始化bean之前执行的代码
properties.putAll(pageHelperProperties()) 这行代码调用了一个PageHelperAutoConfiguration依赖的“bean”,pageHelperProperties()方法被bean修饰。
接下来又是验证环境。
ok,到这里猜测已经得到验证。可是就这?好吧我知道你们想知道它是如何走到循环调用这一步的,我也想知道!接着看 本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。