weixin_40787926
感觉覅
2017-11-28 05:43

SpringBoot不能批量加载mapperLocations!急!在线等!求大神指点啊!

  • mybatis

@Configuration
public class MyBatisConfig {

@Autowired
private BasicDataSource basicDataSource;

@Bean
@ConditionalOnMissingBean //当容器里没有指定的Bean的情况下创建该对象
public SqlSessionFactoryBean sqlSessionFactory() throws IOException {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    // 设置数据源
    sqlSessionFactoryBean.setDataSource(basicDataSource);
    // 设置mybatis的主配置文件
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource mybatisConfigXml = resolver.getResource("classpath:mybatis/SqlMapConfig.xml");
    sqlSessionFactoryBean.setConfigLocation(mybatisConfigXml);
    // 设置别名包
    sqlSessionFactoryBean.setTypeAliasesPackage("com.zeunpro.robot.approbot.pojo");



            //就是这句代码,只能指定单个mapper.xml文件,加通配符的话找不到文件
            sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:mappers/AdminUserMapper.xml"));


    return sqlSessionFactoryBean;
}

}


  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

8条回答