一: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>-->
<!--<!– com.github.pagehelper為PageHelper類所在包名 –>-->
<!--<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即可。