背景:
产品已经上线,目前为了更好的查看线上数据,所以计划开发一套boss运营系统,供内部人员使用,boss系统需要建自己的一套数据表数据结构,初期本来想跟业务表放在一起,但是思前想后,Boss系统表结构和业务数据放在一个数据库不是很合理,所以前期采用动态数据源选择来加载或者操作合法数据。
实现过程:
1.编写application.yml --> mybatisplus配置,mysql多数据源配置。
spring:
application:
name: @spring.application.name@
environment: @spring.application.environment@
datasource.druid:
#数据源1
datasource1:
url: jdbc:mysql:///mds
username: root
password: 123456
filters: config
db-type: mysql
driver-class-name: com.mysql.jdbc.Driver
initial-size: 1
min-idle: 1
max-active: 20
max-wait: 60000
min-evictable-idle-time-millis: 300000
validation-query: SELECT 'x'
test-while-idle: true
test-on-borrow: false
test-on-return: false
pool-prepared-statements: false
max-pool-prepared-statement-per-connection-size: 20
filter:
stat:
enabled: false
wall:
enabled: true
web-stat-filter:
enabled: false
stat-view-servlet:
enabled: false
#数据源1
datasource1:
url: jdbc:mysql:///mds
username: root
password: 123456
filters: config
db-type: mysql
driver-class-name: com.mysql.jdbc.Driver
initial-size: 1
min-idle: 1
max-active: 20
max-wait: 60000
min-evictable-idle-time-millis: 300000
validation-query: SELECT 'x'
te