Browse Source

1.在多数据源的情况下增加 增加
dynamic:
not-url
配置 此配置项下面的url 不参加数据源切库操作
2.更改相关版本号为v1.2.0

gaoyu 2 years ago
parent
commit
cba80c14e2

+ 1 - 1
apm-common/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>apm-parent</artifactId>
         <groupId>com.persagy</groupId>
-        <version>v1.0.0-SNAPSHOT</version>
+        <version>v1.2.0-SNAPSHOT</version>
         <relativePath>../apm-parent</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>

+ 1 - 1
apm-mybatis/pom.xml

@@ -4,7 +4,7 @@
     <parent>
         <groupId>com.persagy</groupId>
         <artifactId>apm-parent</artifactId>
-        <version>v1.0.0-SNAPSHOT</version>
+        <version>v1.2.0-SNAPSHOT</version>
         <relativePath>../apm-parent</relativePath>
     </parent>
     <artifactId>apm-mybatis</artifactId>

+ 20 - 1
apm-mybatis/src/main/java/com/persagy/apm/mybatis/handler/DynamicDataSourceHandler.java

@@ -5,15 +5,20 @@ import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator;
 import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
 import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties;
 import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
+import com.google.common.collect.Lists;
 import com.persagy.apm.common.context.poems.PoemsContext;
 import com.persagy.apm.common.helper.SpringHelper;
 import com.persagy.apm.mybatis.service.IDbService;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.stereotype.Component;
 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
 
+import java.util.List;
+
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.sql.DataSource;
@@ -32,6 +37,7 @@ public class DynamicDataSourceHandler extends HandlerInterceptorAdapter {
      */
     private static final String[] IGNORE_URL = {".html", ".js", ".css", "/swagger-resources"};
 
+
     @Autowired
     private DynamicRoutingDataSource dataSource;
     @Autowired
@@ -40,13 +46,21 @@ public class DynamicDataSourceHandler extends HandlerInterceptorAdapter {
     private DynamicDataSourceProperties defaultProperty;
     @Autowired
     private IDbService dbService;
+    
+    @Value("#{'${dynamic.not-url:}'.split(',')}")
+    private List<String> notUrlList;
 
-    @Override
+	@Override
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
         String requestURI = request.getRequestURI();
         if (StringUtils.containsAny(requestURI, IGNORE_URL)) {
             return true;
         }
+        for (String url : notUrlList) {
+        	if(requestURI.contains(url)) {
+        		 return true;
+        	}
+		}
         resetDataSource();
         return true;
     }
@@ -62,6 +76,11 @@ public class DynamicDataSourceHandler extends HandlerInterceptorAdapter {
         }
         // 默认为应用名
         String dbNameDefault = SpringHelper.getString("spring.application.name");
+        String dynamicDbName = SpringHelper.getString("dynamic.db.name");
+        if(StringUtils.isNotBlank(dynamicDbName)) {
+        	dbNameDefault=dynamicDbName;
+        }
+       
         // 将应用名中的中划线替换为下划线,按照公司要求应用名统一用中划线,数据库名统一用下划线
         dbNameDefault = dbNameDefault.replace("-", "_");
         String newDsName = dbNameDefault;

+ 1 - 1
apm-package/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>apm-parent</artifactId>
         <groupId>com.persagy</groupId>
-        <version>v1.0.0-SNAPSHOT</version>
+        <version>v1.2.0-SNAPSHOT</version>
         <relativePath>../apm-parent</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>

+ 2 - 2
apm-parent/pom.xml

@@ -5,7 +5,7 @@
     <modelVersion>4.0.0</modelVersion>
     <groupId>com.persagy</groupId>
     <artifactId>apm-parent</artifactId>
-    <version>v1.0.0-SNAPSHOT</version>
+    <version>v1.2.0-SNAPSHOT</version>
     <packaging>pom</packaging>
 
     <repositories>
@@ -34,7 +34,7 @@
     </parent>
     <!-- 版本管理 -->
     <properties>
-        <apm.version>v1.0.0-SNAPSHOT</apm.version>
+        <apm.version>v1.2.0-SNAPSHOT</apm.version>
         <platform.version>1.0.0</platform.version>
         <mybatis-plus.version>3.3.1</mybatis-plus.version>
         <dynamic-datasource.version>3.3.2</dynamic-datasource.version>

+ 1 - 1
apm-server/pom.xml

@@ -10,7 +10,7 @@
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <artifactId>apm-server</artifactId>
-
+	<version>v1.2.0-SNAPSHOT</version>
     <dependencies>
         <!-- 集成框架工具类 -->
         <dependency>

+ 1 - 1
apm-translate/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>apm-parent</artifactId>
         <groupId>com.persagy</groupId>
-        <version>v1.0.0-SNAPSHOT</version>
+        <version>v1.2.0-SNAPSHOT</version>
         <relativePath>../apm-parent</relativePath>
     </parent>
     <modelVersion>4.0.0</modelVersion>

+ 1 - 1
pom.xml

@@ -6,7 +6,7 @@
     <parent>
         <groupId>com.persagy</groupId>
         <artifactId>apm-parent</artifactId>
-        <version>v1.0.0-SNAPSHOT</version>
+        <version>v1.2.0-SNAPSHOT</version>
         <relativePath>apm-parent</relativePath>
     </parent>
     <artifactId>apm-basics</artifactId>