/**
* 初始化添加的mybatis
*
* @throws Exception
* @time 2018年8月1日
* @author DoubleLi
*/
private void intMybatisdb() throws Exception {
Configuration configuration = this.sqlSessionFactory.getConfiguration();//session工厂自行注入
Resource[] mapperLocations = new PathMatchingResourcePatternResolver()
.getResources("classpath*:demo/dao/*.xml");//指定目录下的xml
for (Resource configLocation : mapperLocations) {
try {
XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(configLocation.getInputStream(), configuration,
configLocation.toString(), configuration.getSqlFragments());
xmlMapperBuilder.parse();
System.out.println("mapper文件[" + configLocation.getFilename() + "]缓存加载成功");
} catch (IOException e) {
System.out.println("mapper文件[" + configLocation.getFilename() + "]不存在或内容格式不对");
continue;
}
}
}
spring.xml 加入扫描路径包
<context:component-scan base-package="demo"/>