SpringBoot+Druid
依赖引入
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.8</version>
</dependency>
Druid 多数据源配置
-
配置文件配置
-
spring:
datasource:
url: jdbc://mysql:192.168.137.127:3306/test
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
druid:
one:
initial-size: 1
max-active: 20
min-idle: 1
max-wait: 6000
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
validation-query: "select 1 from dual"
validation-query-timeout: 10000
test-on-borrow: false
test-on-return: false
test-while-idle: true
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
max-evictable-idle-time-millis: 600000
filters: "stat,wall"
async-init: true
two:
url: jdbc://mysql:192.168.137.126:3306/test
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
initial-size: 1
max-active: 20
min-idle: 1
max-wait: 6000
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
validation-query: "select 1 from dual"
validation-query-timeout: 10000
test-on-borrow: false
test-on-return: false
test-while-idle: true
time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000
max-evictable-idle-time-millis: 600000
filters: "stat,wall"
async-init: true
-
配置类
-
数据源注入
|