springboot配置多数据源mybatis配置失效问题

mybatis配置

#开启驼峰映射
mybatis.configuration.map-underscore-to-camel-case=true
#开启打印sql
mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

失效处理

    @Bean
    @ConfigurationProperties(prefix = "mybatis.configuration")
    public org.apache.ibatis.session.Configuration globalConfiguration() {
        return new org.apache.ibatis.session.Configuration();
    }

    @Bean
    public SqlSessionFactory sqlSessionFactory(org.apache.ibatis.session.Configuration config) throws Exception {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(myRoutingDataSource);
        sqlSessionFactoryBean.setTypeAliasesPackage("com.bling.dab.domain");
        sqlSessionFactoryBean.setConfiguration(config);
        sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/*.xml"));
        return sqlSessionFactoryBean.getObject();

问题解决,失效原因是配置多数据源,自定义的sqlsessionFactory不会加载mybatis配置,而单数据源的sqlsessionFactory不是自定义的默认去加载了mybatis配置

上一篇:MyBatis-Spring设置不使用事务


下一篇:java – Spring – 如何在不加工列名的情况下使用BeanPropertyRowMapper