项目运行报错信息:
java.lang.IllegalStateException: Failed to load ApplicationContext
具体的报错细节:
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration':
Invocation of init method failed;nested exception is 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?
可见最后一句提示:
Requested bean is currently in creation: Is there an unresolvable circular reference?
在告诉我们,目前的bean在被创建的同时,已经在被引用了!也可以理解为在被引用的同时,又在创建!致使这个Bean是无法被使用的,因此出现:“循环依赖”的情况!
出现问题的原因:
当前的springboot项目的创建版本是最新的,没有对应的pageHelper插件版本来解决这个问题!需要我们把springboot的项目版本降低!
(当你导入的pageHelper插件的版本是:1.3.x,如果你现在的springboot项目版本是2.6.x,需要降至2.5.x的版本)如果pageHelper创建依赖一导入,不做任何动作,启动springboot项目,发送任何请求都会出现上面的“循环依赖”问题的。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
2.7.5属于高版本的springboot,降至2.5.x的版本
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
导入的pageHelper创建的版本是:1.3.0
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.3.0</version>
</dependency>
至此,再次启动项目,项目完美启动!当对查询数据通过`PageHelper.startPage(int pageNum,int pageSize)` 进行分页时,也是可以完美出结果的!