java.lang.ClassCastException: com.github.pagehelper.PageHelpercannot be cast to org.apache.Intercept

在使用PageHelper插件时遇到错误,报错提示无法将PageHelper转换为Interceptor。解决方法是更新mybatis配置,将插件interceptor属性更改为PageInterceptor。
摘要由CSDN通过智能技术生成

使用pagehelper插件时出现的异常。

我原先mybatis的配置如下

<?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE configuration  
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"  
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
	<plugins>
		<plugin interceptor="com.github.pagehelper.PageHelper">
        	<property name="dialect" value="mysql"/>
    	</plugin>
	</plugins>

异常:Error creating bean with name ‘sqlSessionFactory’ defined in file [D:\eclipse-workspace2.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\taotao-manager-web\WEB-INF\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/sqlSessionConfig.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.version>5.1.2</pagehelper.version>

我使用的pagehelper的版本是5.1,5.0之后的版本使用com.github.pagehelper.PageInterceptor这个类。

解决方案:

将mybatis配置文件改为

<?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE configuration  
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"  
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
	<plugins>
		<plugin interceptor="com.github.pagehelper.PageInterceptor"/>
	</plugins>
	
</configuration>

解决

————————————————
版权声明:本文为CSDN博主「IPI715718」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/IPI715718/article/details/83384131

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值