Cause: java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast to org.apache.i
来源:互联网 发布:知乎,京九高铁 编辑:程序博客网 时间:2024/06/05 16:09
问题背景:
在某商城的学习过程中用到的分页插件的版本是4.0以下的版本,基本不支持多边查询的分页,学习资料中是经过高手重新编写的,后来查资料发现最新的5.0及以上的版本已经有了解决方案,便直接用了5.0的版本,除了引用这个pagehelper-x.x.x.jar 和其依赖包 jsqlparser-0.9.5.jar,开始的配置就照着原来的配置在SqlMapConfig.xml进行了配置
<?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> <!-- 配置分页插件 PageHelper --> <plugins> <plugin interceptor="com.github.pagehelper.PageHelper">
<!-- 指定使用的数据库是什么 -->
<property name="dialect"value="mysql"/> </plugin> </plugins> </configuration>
开始运行也没有问题,结果第二天来了就报错了
Exception encountered during context initialization - cancelling refresh attemptorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in file [D:\eclipse\taotao-manager\
taotao-manager-web\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: mysqlat org.
springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1566)
分析
整合后的mybaties和spring都是通过配置文件联系起来的,如果配置文件有问题一些映射就会出错,也就会导致一些class或者bean无法成功生成或找到,这是我当时的第一想法,所以看到
com.github.pagehelper.PageException: java.lang.ClassNotFoundException:
第一想法是SqlMapConfig.xml配置可能有误,核查了一遍依然报错,这时有点蒙了,经过朋友的提醒想是不是版本的问题呢,一搜看到了这篇博客,这篇博客对5.0.2版本的介绍,配置以及使用做了很详细的介绍,发现他用的配置文件的类和我的不一样,他用的是PageInterceptor,我用的是pagehelper。 <bean class="com.github.pagehelper.PageInterceptor"> <!--这里的几个配置主要演示如何使用,如果不理解,一定要去掉下面的配置helperDialect:有别于3.0+版本,现在必须是helperDialect,否则spring启动加载时会报错--> <property name="properties"> <value> helperDialect=mysql reasonable=true supportMethodsArguments=true params=count=countSql autoRuntimeDialect=true </value> </property> </bean>
刚接触不多,于是便按照人的注解把里面的配置去掉了,然后加上了自己的配置,一运行还是报错,有点着急了,没办法,只能继续查资料,又看到一篇博客才发现为什么会报题目中的那个错误,原来PageHelper5.0版本pagehelper是继承了PageMethod和实现了Dialect,PageInterceptor是实现了Interceptor接口
pageHelper是如何在mybatis中工作呢,是通过mybatis的pulgin实现了Interceptor接口,从而获得要执行的sql语句实现分页技术。所以最开始报错能解释了,可改成了PageInterceptor又报错是怎么回事呢,这这篇博客中,才注意到了错误日志里的这句话
Error parsing SQL Mapper Configuration. Cause: com.github.pagehelper.PageException: java.lang.ClassNotFoundException: mysql
我猜测就是这通过读取properties里面的配置文件来自动识别数据库的,至于为什么再次进行声明会报错以后再研究,而且pagehelper也被引到了这个类里面
感悟
碰到一个新的东西时主要还是要学习其工作的原理,版本问题以及一些源码的简单理解
阅读全文
0 0
- Cause: java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast to org.apache.i
- mybatis使用pagehelper分页报错java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast
- com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor和oracle不识别
- java.lang.ClassCastException:org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to org.apache.AnnotationProcesso
- java.lang.ClassCastException:org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to org.apache.AnnotationProcesso
- java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.spri
- java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.spri
- java.lang.ClassCastException: org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to
- java.lang.ClassCastException: org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to
- java.lang.ClassCastException:org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to o
- java.lang.ClassCastException: org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to
- java.lang.ClassCastException:org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to o
- java.lang.ClassCastException: org.apache.commons.dbcp.BasicDataSource cannot be cast to
- java.lang.ClassCastException: org.apache.taglibs.standard.tlv.JstlCoreTLV cannot be cast to javax.se
- java.lang.ClassCastException: org.apache.shiro.web.servlet.ShiroHttpServletRequest cannot be cast to
- java.lang.ClassCastException: org.apache.taglibs.standard.tlv.JstlCoreTLV cannot be cast to javax.se
- java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to
- PageHelper connot be cast to org.apache.ibatis.plugin.Interceptor
- 排序
- 直接插入排序
- sublime text3安装和支持中文fcitx输入
- 键盘获取3个整型数据
- 余弦的两种表示方法:边长和向量
- Cause: java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast to org.apache.i
- POJ 1716 Integer Intervals(差分约束)
- 关于判断输入字符的单词个数的非数组做法
- 如何查看USB设备的VID\PID
- EasyAR+Unity开发(二)HelloAR 项目剖析以及具体使用
- 单双回文(简单来说就是把一个回文字符串劈成两个)
- 云计算笔记二:Hadoop概述
- javascript对象
- C#路径选择及Excel读写操作