PageHelper分页配置sqlMapConfig.xml引起的bug

先看配置文件
<?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>
	<typeAliases>
		<package name="com.music.model" />
	</typeAliases>
	<!-- 配置分页插件 PageHelper -->
	<plugins>
		<plugin interceptor="com.github.pagehelper.PageHelper">
			<property name="dialect" value="mysql" />
		</plugin>
	</plugins>
</configuration>

报错信息

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring/applicationContext.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

说是这个cannot be cast to org.apache.ibatis.plugin.Interceptor导致的错误

修改配置文件

<?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>
	<typeAliases>
		<package name="com.music.model" />
	</typeAliases>
	<!-- 配置分页插件 PageHelper -->
	<plugins>
		<plugin interceptor="com.github.pagehelper.PageInterceptor">
		</plugin>
		<plugin interceptor="com.github.pagehelper.PageHelper">
			<property name="dialect" value="mysql" />
		</plugin>
	</plugins>
</configuration>

加上这个报错仍然没有改变

然后百度查到

PageHelper插件4.0.0以后的版本支持自动识别使用的数据库,可以不用配置 <property name="dialect" value="mysql"/>

然后去掉这一段

	<plugin interceptor="com.github.pagehelper.PageHelper">
			<!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库 -->
			<property name="dialect" value="mysql" />
		</plugin>

完美启动。

猜你喜欢

转载自blog.csdn.net/mint6/article/details/80616497
今日推荐