多数据源配置
springboot+mybatis 多数据源配置
ENV:springboot 1.X-2.X mybatis-starter版本跟随springboot内置。
编写配置文件
配置文件格式:yml
spring:
datasource:
master:
url: jdbc:sqlserver://localhost:1433;Database=testMasterDB
username: sa
password: 123456
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
slave:
url: jdbc:mysql://localhost:3306/testSlaveDB?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
修改DataSource自动注入
将程序主入口 main方法的入口上删除自动注入
@SpringBootApplication(exclude = {
DataSourceAutoConfiguration<