springboot2.x mybatis多數據源實現

springboot版本:2.1.1.RELEASE

啓動日誌:

運行日誌:

 附上配置信息

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下載地址

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章