记录springBoot使用多数据源
- 引入依赖
<dependency>
<groupId>com.louislivi.fastdep</groupId>
<artifactId>fastdep-datasource</artifactId>
<version>1.0.2</version>
</dependency>
- yml模板
fastdep:
datasource:
test: #数据源名称可随意取
mapper: com.louislivi.fastdep.test.mapper.test #当前数据源对应的mapper目录不能多个数据源相同
password: 123456
url: jdbc:mysql://127.0.0.1:3306/douyin?serverTimezone=Asia/Chongqing&useLegacyDatetimeCode=false&nullNamePatternMatchesAll=true&zeroDateTimeBehavior=CONVERT_TO_NULL&tinyInt1isBit=false&autoReconnect=true&useSSL=false&pinGlobalTxToPhysicalConnection=true
driverClassName: com.mysql.cj.jdbc.Driver
username: root
# # 下面为druid连接池的补充设置
# initialSize: 10
# minIdle: 5
# maxActive: 100
# connectionInitSqls: 'set names utf8mb4;'
test2: #数据源名称可随意取
mapper: com.louislivi.fastdep.test.mapper.test2 #当前数据源对应的mapper目录不能多个数据源相同
password: 123456
url: jdbc:mysql://127.0.0.1:3306/test2?serverTimezone=Asia/Chongqing&useLegacyDatetimeCode=false&nullNamePatternMatchesAll=true&zeroDateTimeBehavior=CONVERT_TO_NULL&tinyInt1isBit=false&autoReconnect=true&useSSL=false&pinGlobalTxToPhysicalConnection=true
driverClassName: com.mysql.cj.jdbc.Driver
username: root
# # 下面为druid连接池的补充设置
# initialSize: 10
# minIdle: 5
# maxActive: 100
# connectionInitSqls: 'set names utf8mb4;'
.