pagehelper 插件应用报错:ConversionNotSupportedException: Failed to convert property value of type ‘java.la
2017-06-30 11:24
495 查看
Mybatis物理分页插件PageHelper 5.0
分类:springmaven(666) (1)
昨天在Maven管理的项目中集成PageHelper的时候总是没有成功。我采用的是Spring的集成方式。
因为我使用的是PageHelper5.0,如果按照这样的配置的话,Log就会报出如下异常:
Error creating bean with name ‘sqlSessionFactory’ defined in class path resource
[META-INF/spring/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException:
Failed to convert property value of type ‘java.lang.Object[]’ to required type ‘org.apache.ibatis.plugin.Interceptor[]’ for property ‘plugins’;
nested exception is java.lang.IllegalStateException:
Cannot convert value of type ‘com.github.pagehelper.PageHelper’ to required type ‘org.apache.ibatis.plugin.Interceptor’ for property ‘plugins[0]’: no matching editors or conversion strategy found
大致意思就是没办法转型成org.apache.ibatis.plugin.Interceptor,在这里我就不明白了,因为网上的教程基本都是这么配置的。
然后我就换一种方式,采用mybatis集成方式进行配置,结果还是出错。内容描述基本差不多。到这里我就很纳闷了,我还特意打开源码,发现确实有PageHelper这个包啊。
然后我打开org.mybatis.spring.SqlSessionFactoryBean找到plugins的具体传参看见
if (!isEmpty(this.plugins)) { for (Interceptor plugin : this.plugins) { configuration.addInterceptor(plugin); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Registered plugin: '" + plugin + "'"); } } }
这里我发现plugin是Interceptor,没办法,只能在github上找最新的PageHelper的文档了。
突然发现这儿坑还挺多的。下面我就把PageHelper 5.0与以前版本不一样的地方给贴出来。
使用 QueryInterceptor 规范 处理分页逻辑 新的分页插件拦截器为
com.github.pagehelper.PageInterceptor 新的 PageHelper 是一个特殊的 Dialect
实现类,以更友好的方式实现了以前的功能 新的分页插件仅有 dialect 一个参数,默认的 dialect 实现类为 PageHelper
PageHelper 仍然支持以前提供的参数,在最新的使用文档中已经全部更新 PageHelper 的 helperDialect 参数和以前的 dialect 功能一样,具体可以看文档的参数说明
增加了基于纯 RowBounds 和 PageRowBounds 的分页实现,在com.github.pagehelper.dialect.rowbounds 包中,这是用于作为 dialect 参数示例的实现,后面会补充更详细的文档 去掉了不适合出现在分页插件中的 orderby功能,以后会提供单独的排序插件
去掉了PageHelper 中不常用的方法新的文档,更新历来更新日志中提到的重要内容,提供英文版本文档 解决 bug 将 Db2RowDialect 改为Db2RowBoundsDialect 所有分页插件抛出的异常改为 PageException
然后他给的Demo中配置是这样的。
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="plugins"> <array> ```ruby <bean class="com.github.pagehelper.PageInterceptor"> ``` <property name="properties"> <!--使用下面的方式配置参数,一行配置一个 --> <value> params=value1 </value> </property> </bean> </array> </property> </bean>
还有一个小坑需要注意的是,在5.0中使用了helperDialect代替了原来的dialect属性。
相关文章推荐
- org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.la
- Spring 整合 Flex (BlazeDS)无法从as对象 到 Java对象转换的异常:org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.Date' to required type 'java.sql.Timestamp' for property 'wfsj'; nested exception is java.lang.Ill
- Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for pr
- Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for pr
- spring Failed to convert property value of type 'java.lang.String' to required type 'int' for proper
- spring Failed to convert property value of type 'java.lang.String' to required type 'int' for proper
- springmvc-- Failed to convert property value of type 'java.lang.String' to required type
- Failed to convert property value of type [java.lang.String] to required type [boolean] for property
- Failed to convert property value of type 'java.util.LinkedHashMap' to required
- Failed to convert property value of type [java.lang.String] to required type [int]
- spring mvc 数据绑定报错 Failed to convert property value of type 'java.lang.String' to required type 'int'
- 关于springMVC中:Failed to convert property value of type 'java.lang.String' to required type 'java.util
- Failed to convert property value of type 'java.util.Properties' to required type 'org.springframewor
- Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for pr
- 表单提交时候"Failed to convert property value of type [java.lang.String] to
- 三、Failed to convert property value of type [org.apache.commons.dbcp.BasicDataSource] to required
- Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching e
- Failed to convert property value of type [com.sun.proxy.$Proxy27 implementing com.ibeifeng.se
- Failed to convert property value of type [$Proxy0 implementing com.s2hs.dao.UserDAO
- mybatis 5.0 报错 Cannot convert value of type ‘com.github.pagehelper.PageHelper’ to required type ‘org