|
@@ -1,5 +1,6 @@
|
|
|
package com.emato.cus.supervise.config.ds.third;
|
|
|
|
|
|
+import com.emato.cus.supervise.config.ds.second.SecondMybatisConfigProperties;
|
|
|
import com.emato.cus.supervise.util.YmlUtils;
|
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
import org.mybatis.spring.SqlSessionFactoryBean;
|
|
@@ -12,6 +13,7 @@ import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.core.env.PropertyResolver;
|
|
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
|
|
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
|
|
+import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
|
@@ -25,14 +27,24 @@ import javax.sql.DataSource;
|
|
|
* @author Scott Chen
|
|
|
* @date 2017/4/22
|
|
|
*/
|
|
|
+@EnableTransactionManagement(order = 2)
|
|
|
@Configuration
|
|
|
public class ThirdDataSourceConfig {
|
|
|
|
|
|
- // yml方式配置
|
|
|
- public static final String MYBATIS_MAPPER_CONFIG_YML_PATH = "application.yml";
|
|
|
-
|
|
|
@Autowired
|
|
|
- private PropertyResolver propertyResolver;
|
|
|
+ private ThirdMybatisConfigProperties thirdMybatisConfigProperties;
|
|
|
+
|
|
|
+ // -------------------- mybatis 属性配置 --------------------
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ @ConfigurationProperties(prefix = "mybatis.third")
|
|
|
+ public ThirdMybatisConfigProperties thirdMybatisConfigProperties(){
|
|
|
+ return new ThirdMybatisConfigProperties();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // -------------------- 其它业务库 --------------------
|
|
|
+
|
|
|
|
|
|
@Bean
|
|
|
public DataSource thirdDataSource() {
|
|
@@ -49,12 +61,11 @@ public class ThirdDataSourceConfig {
|
|
|
public SqlSessionFactory thirdSqlSessionFactory(DataSource thirdDataSource) throws Exception {
|
|
|
SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
|
|
|
sessionFactoryBean.setDataSource(thirdDataSource);
|
|
|
- //Mybatis XML配置文件
|
|
|
- sessionFactoryBean.setConfigLocation(new PathMatchingResourcePatternResolver()
|
|
|
- .getResource(configLocationByYml()));
|
|
|
- sessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver()
|
|
|
- .getResources(mapperLocationsByYml()));
|
|
|
- sessionFactoryBean.setTypeAliasesPackage(typeAliasesByYml());
|
|
|
+
|
|
|
+ sessionFactoryBean.setConfigLocation(new PathMatchingResourcePatternResolver().getResource(thirdMybatisConfigProperties.getConfigLocation()));
|
|
|
+ sessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(thirdMybatisConfigProperties.getMapperLocationsConfig()));
|
|
|
+ sessionFactoryBean.setTypeAliasesPackage(thirdMybatisConfigProperties.getTypeAliasesPackage());
|
|
|
+
|
|
|
return sessionFactoryBean.getObject();
|
|
|
}
|
|
|
|
|
@@ -68,23 +79,4 @@ public class ThirdDataSourceConfig {
|
|
|
return new SqlSessionTemplate(thirdSqlSessionFactory);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- private String configLocationByYml() {
|
|
|
- String path = MYBATIS_MAPPER_CONFIG_YML_PATH;
|
|
|
- String key = "mybatis.third.config-location";
|
|
|
- return YmlUtils.instance().getValue(key, path);
|
|
|
- }
|
|
|
-
|
|
|
- private String mapperLocationsByYml() {
|
|
|
- String path = MYBATIS_MAPPER_CONFIG_YML_PATH;
|
|
|
- String key = "mybatis.third.mapper-locations-config";
|
|
|
- return YmlUtils.instance().getValue(key, path);
|
|
|
- }
|
|
|
-
|
|
|
- private String typeAliasesByYml() {
|
|
|
- String path = MYBATIS_MAPPER_CONFIG_YML_PATH;
|
|
|
- String key = "mybatis.third.type-aliases-package";
|
|
|
- return YmlUtils.instance().getValue(key, path);
|
|
|
- }
|
|
|
-
|
|
|
}
|