SpringBoot、mysql配置PageHelper插件

一:https://blog.csdn.net/h985161183/article/details/79800737

主要异常:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration': 

pageHelper.jar版本与MyBatis版本不兼容;换用高版本jar包

我用的SpringBoot版本:

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

pageHelper版本:

<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>

二:https://blog.csdn.net/s592652578/article/details/78179998

主要异常信息:com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor
我的配置

<plugins>
  <plugin interceptor="com.github.pagehelper.PageHelper">
  <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库-->
  <property name="dialect" value="mysql"/>
  </plugin>
</plugins>

解决:配置中实现的是com.github.pagehelper.PageHelper这个接口,而错误报的是这个借口在强转成org.apache.ibatis.plugin.Interceptor这个借口的时候报错了,而我使用的是pageheper5.1.2版本,上网一查,自4.0.0版本以后就不再实现这个接口了,转而实现这个接口:org.apache.ibatis.plugin.Interceptor,因此,修改配置如下:

<plugins>
  <plugin interceptor="com.github.pagehelper.PageInterceptor">
  <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库--> 
  <property name="dialect" value="mysql"/>
  </plugin>
</plugins>

又报异常:主要是mysql类不识别,最终原因还是因为版本的问题,自4.0.0以后的版本已经可以自动识别数据库了,所以不需要我们再去指定数据库,所以,修改配置:
<plugins>
  <plugin interceptor="com.github.pagehelper.PageInterceptor">
  </plugin>
</plugins>
三:之后的异常:java.lang.RuntimeException: 在系统中发现了多个分页插件,请检查系统配置!

删除mybatis-config.xml文件中的pagehelper就好了
<!--<plugins>-->
<!--&lt;!&ndash; com.github.pagehelper为PageHelper类所在包名 &ndash;&gt;-->
<!--<plugin interceptor="com.github.pagehelper.PageInterceptor">-->
<!--</plugin>-->
<!--</plugins>-->

https://blog.csdn.net/boke7265/article/details/80863010

总结:SpringBoot、mysql配置PageHelper插件,只需要使用 2.0.4.RELEASE版本SpringBoot引入1.2.5版本pageHelper即可。

猜你喜欢

转载自www.cnblogs.com/zhangliwei/p/9575867.html
今日推荐