Springboot项目分页插件问题报错
在系统中发现了多个分页插件,请检查系统配置!
问题描述:
在系统中发现了多个分页插件,请检查系统配置!
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
@Bean(name = "oracleSqlSessionFactory")
@Primary
public SqlSessionFactory oracleSqlSessionFactory(@Qualifier("oracleDataSource") DataSource dataSource) throws Exception {
MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
MybatisConfiguration cfg = new MybatisConfiguration();
//此处引入了分页插件拦截器
***cfg.addInterceptor(pageInterceptor());***
cfg.addInterceptor(mybatisSqlInterceptor());
cfg.setMapUnderscoreToCamelCase(true);
cfg.setCacheEnabled(true);
cfg.setCallSettersonNulls(true);
GlobalConfiguration gc = new GlobalConfiguration();
gc.setKeyGenerator(new OracleKeyGenerator());
gc.setIdType(IdType.AUTO.getKey());
gc.setDbType(DBType.ORACLE.getDb());
gc.setDbColumnUnderline(true);
bean.setConfiguration(cfg);
bean.setGlobalConfig(gc);
bean.setDataSource(dataSource);
//设置oracle数据源mapper文件路径
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/oracle/*.xml"));
bean.setTypeAliasesPackage("com.ping.ipss.entity");
return bean.getObject();
}
private PageInterceptor pageInterceptor() {
// 分页查询参数设置
PageInterceptor pageInterceptor = new PageInterceptor();
Properties properties = new Properties();
// 是否将参数offset作为PageNum使用
// properties.setProperty("offsetAsPageNum", "true");
// //是否进行count查询
// properties.setProperty("rowBoundsWithCount", "true");
properties.setProperty("helperDialect", "oracle");
//是否分页合理化
properties.setProperty("reasonable", "true");
properties.setProperty("supportMethodsArguments", "true");
properties.setProperty("params", "count=countSql");
pageInterceptor.setProperties(properties);
return pageInterceptor;
}
原因分析: 这是因为springboot自动引入了默认的分页插件,在数据源配置时再加入了分页插件, 导致有多个分页插件而报错
解决方案:
**第一种方法:**在启动类上加注解排除自动注入的分页拦截器:
@SpringBootApplication(exclude = {PageHelperAutoConfiguration.class})
**第二种方法:**改用mybatisplus的分页拦截器:
private PaginationInterceptor paginationInterceptor() {
PaginationInterceptor page = new PaginationInterceptor();
page.setDialectType(DBType.ORACLE.getDb());
page.setLocalPage(true);
return page;
}



