@Slf4j @Configuration @MapperScan(basePackages = MerchantDruidConfig.PACKAGE, sqlSessionTemplateRef = "merchantSqlSessionTemplate") public class MerchantDruidConfig { static final String PACKAGE = "com.xx.mapper"; static final String MAPPER_LOCATION = "classpath*:xml/*.xml"; @Autowired @Qualifier(DruidConfig.MERCHANT_DATASOURCE_BEAN_NAME) private DataSource merchant; @Bean("merchantSqlSessionFactory") public SqlSessionFactory getSqlSessionFactory() throws Exception { MybatisSqlSessionFactoryBean factoryBean = new MybatisSqlSessionFactoryBean(); factoryBean.setDataSource(merchant); MybatisConfiguration configuration = new MybatisConfiguration(); configuration.setDefaultScriptingLanguage(MybatisXMLLanguageDriver.class); configuration.setJdbcTypeForNull(JdbcType.NULL); factoryBean.setConfiguration(configuration); factoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MerchantDruidConfig.MAPPER_LOCATION)); return factoryBean.getObject(); } @Bean("merchantSqlSessionTemplate") public SqlSessionTemplate getSqlSessionTemplate() throws Exception { SqlSessionTemplate template = new SqlSessionTemplate(getSqlSessionFactory()); return template; } }
Druid配置多数据源
最新推荐文章于 2024-04-19 05:59:00 发布