栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

(BUG集)Springboot项目分页插件问题报错

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

(BUG集)Springboot项目分页插件问题报错

项目场景:

Springboot项目分页插件问题报错
在系统中发现了多个分页插件,请检查系统配置!


问题描述:

在系统中发现了多个分页插件,请检查系统配置!
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

Error querying database. Cause: java.lang.RuntimeException: 在系统中发现了多个分页插件,请检查系统配置! Cause: java.lang.RuntimeException: 在系统中发现了多个分页插件,请检查系统配置!
    @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;
    }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/490664.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号