最近springboot后端工程想实现分页查询,添加pagehelper后突然启动报错,如下:
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration': Requested bean is currently in creation: Is there an unresolvable circular reference?
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.beforeSingletonCreation(DefaultSingletonBeanRegistry.java:355)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:227)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:410)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
。。。。。。
经过多方排查发现是因为springboot自2.6版开始默认禁止Bean的循环引用,其实官方的目的也是为了鼓励大家不要循环依赖,但素.....像我这样的人就比较懒,习惯了之前的写法怎么办呢???
改默认配置,将默认的配置改了不就行了,如下在yml文件中添加即可:
spring main: allow-circular-references: false
启动程序,丝滑如初....