master
无限超频 6 years ago
parent 8b8a0abd0e
commit 69dab0ec97
  1. 5
      mybatis/src/main/java/config/MyBatisConfig.java

@ -7,6 +7,7 @@ import model.DataSourceModel;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.Configuration;
import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
@ -86,6 +87,10 @@ public class MyBatisConfig extends InitConfig {
try { try {
if(factoryBean.getObject()!=null){ if(factoryBean.getObject()!=null){
beanFactory.registerSingleton(dataSourceModel.getFactoryBean(), factoryBean.getObject()); beanFactory.registerSingleton(dataSourceModel.getFactoryBean(), factoryBean.getObject());
SqlSessionTemplate sqlSessionTemplate=new SqlSessionTemplate(factoryBean.getObject());
sqlSessionTemplate.getConfiguration().getMapperRegistry().getMappers().forEach(c->{
beanFactory.registerSingleton(dataSourceModel.getFactoryBean()+c.getSimpleName(),sqlSessionTemplate.getMapper(c));
});
}else{ }else{
LOG.error("初始化数据库配置" + JSON.toJSONString(dataSourceModel) + "失败"); LOG.error("初始化数据库配置" + JSON.toJSONString(dataSourceModel) + "失败");
} }

Loading…
Cancel
Save