mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
完成多数据源配置
This commit is contained in:
parent
8a9c714586
commit
a1b7697eb3
9
pom.xml
9
pom.xml
@ -46,6 +46,7 @@
|
||||
<easyexcel.verion>2.2.7</easyexcel.verion>
|
||||
<velocity.version>2.2</velocity.version>
|
||||
<screw.version>1.0.5</screw.version>
|
||||
<dynamic-datasource.version>3.3.2</dynamic-datasource.version>
|
||||
</properties>
|
||||
|
||||
<!-- 依赖声明 -->
|
||||
@ -271,6 +272,14 @@
|
||||
<version>${screw.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 多数据源 -->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
|
||||
<version>${dynamic-datasource.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
@ -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";
|
||||
}
|
@ -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:
|
||||
|
@ -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 的请求
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user