自定义SqlSessionFactory时mybatis-config.xml失效

使用场景:

使用多数据源时,自定义创建SqlSessionFactory对象,没有正确读取到mybatis-config.xml配置,导致下划线驼峰映射失效,sql语句输出不显示等问题。

解决方案:

    @Bean(name = "UserSqlSessionFactory")
    public SqlSessionFactory dataLgSqlSessionFactory(@Qualifier("UserDataDataSource") DataSource dataSource, MybatisProperties mybatisProperties) throws Exception {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/user/**/*.xml"));
        bean.setConfigLocation(new ClassPathResource("mybatis-config.xml"));
        return bean.getObject();
    }

 mybatis-config.xml文件:




    
        
        
          
        
        
    



你可能感兴趣的:(Java,java,开发语言)