PageHelper:com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in file [...省略...spring\applicationContext-dao.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: 
Failed to parse config resource: class path resource [mybatis/SqlMapConfig.xml]; 
nested exception is org.apache.ibatis.builder.BuilderException: 
Error parsing SQL Mapper Configuration. 
Cause: java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor
......
Caused by: org.springframework.core.NestedIOException: 
Failed to parse config resource: class path resource [mybatis/SqlMapConfig.xml]; 
nested exception is org.apache.ibatis.builder.BuilderException: 
Error parsing SQL Mapper Configuration. Cause: java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor

	

项目启动之后出现的这个错误,也挺奇怪的,因为之前是没有出现这个错误的。

看了一眼自己使用的PageHelper版本:<pagehelper.version>5.1.2</pagehelper.version>,好像是改过的,因为之前用的是3.X.X.

改回来,其实就能用了,然而既然这个5.X.X出现错误,那还是找找看看是为啥吧。

先上maven仓库,搜PageHelper

点进去,找到自己使用的版本号。

点进链接

中文文档比较适合我......

先找个 demo 看看:

新版本的PagHelper,使用的是PageIntercepter,不是之前的PageHelper,从文档上看,似乎连dialect也不用配置。

试一下:

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

重新启动:

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sqlSessionFactory' defined in file [......\target\classes\spring\applicationContext-dao.xml]: 
Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: 
Failed to parse config resource: class path resource [mybatis/SqlMapConfig.xml]; 
nested exception is org.apache.ibatis.builder.BuilderException: 
Error parsing SQL Mapper Configuration. 
Cause: com.github.pagehelper.PageException: java.lang.ClassNotFoundException: mysql
......
Caused by: org.apache.ibatis.builder.BuilderException: 
Error parsing SQL Mapper Configuration. 
Cause: com.github.pagehelper.PageException: java.lang.ClassNotFoundException: mysql

好吧,好像真跟 dialet 的配置有关,去掉配置试试。

正常了!

附上PageHelper新版本的使用文档。

https://github.com/pagehelper/Mybatis-PageHelper/blob/master/wikis/zh/HowToUse.md

发布了95 篇原创文章 · 获赞 16 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/tiankong_12345/article/details/90269787