|
@@ -0,0 +1,43 @@
|
|
|
+package com.smppw.analysis.infrastructure.config;
|
|
|
+
|
|
|
+import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
+import org.mybatis.spring.SqlSessionFactoryBean;
|
|
|
+import org.mybatis.spring.SqlSessionTemplate;
|
|
|
+import org.mybatis.spring.annotation.MapperScan;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
+import org.springframework.boot.jdbc.DataSourceBuilder;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.context.annotation.Primary;
|
|
|
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
|
|
+
|
|
|
+import javax.sql.DataSource;
|
|
|
+
|
|
|
+@Configuration
|
|
|
+@MapperScan(basePackages = {"com.smppw.analysis.domain.mapper.core"}, sqlSessionFactoryRef = "coreSqlSessionFactory")
|
|
|
+public class CoreDataSourceConfig {
|
|
|
+ @Bean("coreDataSource")
|
|
|
+ @Primary
|
|
|
+ @ConfigurationProperties(prefix = "spring.datasource.core")
|
|
|
+ public DataSource coreDataSource() {
|
|
|
+ return DataSourceBuilder.create().build();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean(name = "coreSqlSessionFactory")
|
|
|
+ @Primary
|
|
|
+ public SqlSessionFactory coreSqlSessionFactory(@Qualifier("coreDataSource") DataSource datasource)
|
|
|
+ throws Exception {
|
|
|
+ SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
|
|
|
+ bean.setDataSource(datasource);
|
|
|
+ bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:mapping/core/*.xml"));
|
|
|
+ return bean.getObject();// 设置mybatis的xml所在位置
|
|
|
+ }
|
|
|
+
|
|
|
+ @Bean("coreSqlSessionTemplate")
|
|
|
+ @Primary
|
|
|
+ public SqlSessionTemplate coreSqlSessionTemplate(
|
|
|
+ @Qualifier("coreSqlSessionFactory") SqlSessionFactory sessionFactory) {
|
|
|
+ return new SqlSessionTemplate(sessionFactory);
|
|
|
+ }
|
|
|
+}
|