diff --git a/pom.xml b/pom.xml
index 96e0e08ce..102182921 100644
--- a/pom.xml
+++ b/pom.xml
@@ -46,6 +46,7 @@
2.2.7
2.2
1.0.5
+ 3.3.2
@@ -271,6 +272,14 @@
${screw.version}
+
+
+ com.baomidou
+ dynamic-datasource-spring-boot-starter
+ ${dynamic-datasource.version}
+
+
+
diff --git a/src/main/java/cn/iocoder/dashboard/framework/datasource/enums/DatasourceMark.java b/src/main/java/cn/iocoder/dashboard/framework/datasource/enums/DatasourceMark.java
new file mode 100644
index 000000000..3b1e81763
--- /dev/null
+++ b/src/main/java/cn/iocoder/dashboard/framework/datasource/enums/DatasourceMark.java
@@ -0,0 +1,11 @@
+package cn.iocoder.dashboard.framework.datasource.enums;
+
+/**
+ * 对应于多数据源中不同数据源配置
+ *
+ * 在方法上使用注解{@code @DS(DatasourceMark.slave)}可以指定slave数据源,默认是master数据源
+ */
+public interface DatasourceMark {
+ String master = "master";
+ String slave = "slave";
+}
diff --git a/src/main/resources/application-dev.yaml b/src/main/resources/application-dev.yaml
index b0a96fb04..c3a01100f 100644
--- a/src/main/resources/application-dev.yaml
+++ b/src/main/resources/application-dev.yaml
@@ -4,13 +4,11 @@ server:
--- #################### 数据库相关配置 ####################
spring:
- # 数据源配置项 TODO 多数据源;TODO 监控配置
+ # 数据源配置项 TODO 监控配置
+ # 排除默认的自动配置,使用dynamic-datasource-spring-boot-starter配置多数据源,整合druid
+ autoconfigure:
+ exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
datasource:
- name: ruoyi-vue-pro
- url: jdbc:mysql://400-infra.server.iocoder.cn:3306/${spring.datasource.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
- driver-class-name: com.mysql.jdbc.Driver
- username: root
- password: 3WLiVUBEwTbvAfsh
druid:
web-stat-filter:
enabled: true
@@ -32,6 +30,34 @@ spring:
wall:
config:
multi-statement-allow: true
+ dynamic:
+ # druid全局配置 https://dynamic-datasource.com/en/guide/integration/Druid.html#configurate-parameters
+# druid: #The following are the supported global parameters
+# initial-size:
+# max-active:
+# min-idle:
+# max-wait:
+ primary: master
+ datasource:
+ master:
+ name: ruoyi-vue-pro
+ url: jdbc:mysql://400-infra.server.iocoder.cn:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
+ driver-class-name: com.mysql.jdbc.Driver
+ username: root
+ password: 3WLiVUBEwTbvAfsh
+ # druid 局部配置
+# druid: # The following are independent parameters that can be reset for each db
+# validation-query: select 1 FROM DUAL #such as oracle need this
+# slave:
+# name: ruoyi-vue-pro-slave
+# url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
+# driver-class-name: com.mysql.jdbc.Driver
+# username: root
+# password: 123456
+
+
+
+
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
redis:
diff --git a/src/main/resources/application-local.yaml b/src/main/resources/application-local.yaml
index fdb260758..0c5d8cfa8 100644
--- a/src/main/resources/application-local.yaml
+++ b/src/main/resources/application-local.yaml
@@ -4,13 +4,11 @@ server:
--- #################### 数据库相关配置 ####################
spring:
- # 数据源配置项 TODO 多数据源;TODO 监控配置
+ # 数据源配置项 TODO 监控配置
+ # 排除默认的自动配置,使用dynamic-datasource-spring-boot-starter配置多数据源,整合druid
+ autoconfigure:
+ exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
datasource:
- name: ruoyi-vue-pro
- url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
- driver-class-name: com.mysql.jdbc.Driver
- username: root
- password: 123456
druid:
web-stat-filter:
enabled: true
@@ -32,6 +30,32 @@ spring:
wall:
config:
multi-statement-allow: true
+ dynamic:
+ # druid全局配置 https://dynamic-datasource.com/en/guide/integration/Druid.html#configurate-parameters
+# druid: #The following are the supported global parameters
+# initial-size:
+# max-active:
+# min-idle:
+# max-wait:
+ primary: master
+ datasource:
+ master:
+ name: ruoyi-vue-pro
+ url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
+ driver-class-name: com.mysql.jdbc.Driver
+ username: root
+ password: 123456
+ # druid 局部配置
+# druid: # The following are independent parameters that can be reset for each db
+# validation-query: select 1 FROM DUAL #such as oracle need this
+# slave:
+# name: ruoyi-vue-pro-slave
+# url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
+# driver-class-name: com.mysql.jdbc.Driver
+# username: root
+# password: 123456
+
+
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
redis:
@@ -77,9 +101,9 @@ apollo:
eagerLoad:
enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置
jdbc: # 自定义的 JDBC 配置项,用于数据库的地址
- url: ${spring.datasource.url}
- username: ${spring.datasource.username}
- password: ${spring.datasource.password}
+ url: ${spring.datasource.dynamic.datasource.master.url}
+ username: ${spring.datasource.dynamic.datasource.master.username}
+ password: ${spring.datasource.dynamic.datasource.master.password}
--- #################### 服务保障相关配置 ####################
@@ -161,3 +185,11 @@ yudao:
exclude-urls: # 如下两个 url,仅仅是为了演示,去掉配置也没关系
- ${spring.boot.admin.context-path}/** # 不处理 Spring Boot Admin 的请求
- ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求
+
+
+
+
+
+
+
+