Joburgess 4 年之前
父节点
当前提交
976827b0ba

+ 1 - 1
edu-auth/edu-auth-server/src/main/java/com/keao/edu/auth/AuthServerApplication.java

@@ -16,7 +16,7 @@ import org.springframework.web.client.RestTemplate;
 @SpringBootApplication
 @EnableDiscoveryClient
 @EnableFeignClients({"com.keao.edu"})
-@MapperScan("com.keao.edu.auth.dal.dao")
+@MapperScan({"com.keao.edu.auth.dal.dao", "com.keao.edu.common.dao"})
 @ComponentScan(basePackages="com.keao.edu")
 @Configuration
 @EnableSwagger2Doc

+ 2 - 1
edu-auth/edu-auth-server/src/main/resources/application.yml

@@ -65,7 +65,8 @@ spring:
         min-idle: 1
 
 mybatis:
-  mapperLocations: classpath:config/mybatis/*.xml
+  mapperLocations: classpath*:config/mybatis/*.xml
+  typeAliasesPackage: com.keao.edu.*.entity
 
 swagger:
   base-package: 'com.keao.edu.auth.web.controller'

+ 13 - 9
edu-datasource/src/main/java/com/keao/edu/datasource/DataSourceConfig.java

@@ -1,12 +1,9 @@
 package com.keao.edu.datasource;
 
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.sql.DataSource;
-
+import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
 import org.mybatis.spring.SqlSessionFactoryBean;
 import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -16,13 +13,20 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
 import org.springframework.transaction.PlatformTransactionManager;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 
-import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
+import javax.sql.DataSource;
+import java.util.HashMap;
+import java.util.Map;
 
 @EnableTransactionManagement
 @Configuration
-@MapperScan("com.keao.edu.*.dao")
+@MapperScan("com.keao.edu.datasource.dao")
 public class DataSourceConfig {
 
+	@Value("${mybatis.mapperLocations}")
+	private String resourcePath;
+	@Value("${mybatis.typeAliasesPackage}")
+	private String typeAliasesPackage;
+
 	@Bean("master")
 	@Primary
 	@ConfigurationProperties(prefix = "spring.datasource") // application.yml中对应属性的前缀
@@ -45,8 +49,8 @@ public class DataSourceConfig {
 		SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
 		// 配置动态数据源,如果没有将 dynamicDataSource 作为数据源则不能实现切换
 		sqlSessionFactoryBean.setDataSource(dynamicDataSource());
-		sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath*:config/mybatis/*.xml"));
-		sqlSessionFactoryBean.setTypeAliasesPackage("com.keao.edu.*.entity");
+		sqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(resourcePath));
+		sqlSessionFactoryBean.setTypeAliasesPackage(typeAliasesPackage);
 
 		return sqlSessionFactoryBean;
 	}

+ 2 - 1
edu-user/edu-user-server/src/main/resources/application.yml

@@ -75,7 +75,8 @@ spring:
         min-idle: 1
 
 mybatis:
-  mapperLocations: classpath:config/mybatis/*.xml
+  mapperLocations: classpath*:config/mybatis/*.xml
+  typeAliasesPackage: com.keao.edu.*.entity
   configuration:
     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl