天天看點

springboot2.x mybatis多資料源實作

springboot版本:2.1.1.RELEASE
           

啟動日志:

springboot2.x mybatis多資料源實作

運作日志:

springboot2.x mybatis多資料源實作

 附上配置資訊

server.port=8001
server.servlet.context-path=/dev

#資料源配置(預設)
#useSSL=false MySQL在高版本需要指明是否進行SSL連接配接(不加第一次連接配接資料庫會有警告資訊)
spring.datasource.driver=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://192.168.0.123:3306/test001?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=root

#ds1,ds2 其他兩個資料源
slave.datasource.names=ds1,ds2
#ds1
slave.datasource.ds1.driver=com.mysql.cj.jdbc.Driver
slave.datasource.ds1.url=jdbc:mysql://192.168.0.123:3306/slave1?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
slave.datasource.ds1.username=root
slave.datasource.ds1.password=root
#ds2
slave.datasource.ds2.driver=com.mysql.cj.jdbc.Driver
slave.datasource.ds2.url=jdbc:mysql://192.168.0.123:3306/slave2?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false
slave.datasource.ds2.username=root
slave.datasource.ds2.password=root

# 下面為連接配接池的補充設定,應用到上面所有資料源中
spring.datasource.maximum-pool-size=100
spring.datasource.max-idle=10
spring.datasource.max-wait=10000
spring.datasource.min-idle=5
spring.datasource.initial-size=5
spring.datasource.validation-query=SELECT 1
spring.datasource.test-on-borrow=false
spring.datasource.test-while-idle=true
spring.datasource.time-between-eviction-runs-millis=18800

#mapper.xml檔案
mybatis.mapper-locations=classpath:mapper/*.xml
           

springboot2.x整合mybatis動态資料源:demo下載下傳位址