环境:springBoot2.4.5 IDEA
数据库:Mysql8.0.21
主要任务:多数据源配置Hikari + MybatisPlus
项目结构

注意要点
两个数据源的mapperScan目录一定要分开,否则就会出现数据源1中的表去数据源2数据库中查询的情况
原因:在mapperScan的过程中会把扫描到的类归属于正在配置的某一个数据源,而不会智那区分
application.yml配置
spring:
datasource:
user:
jdbc-url: jdbc:mysql://localhost:3306/testOneDB?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true&allowMultiQueries=true
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
type: com.zaxxer.hikari.HikariDataSource
hikari:
pool-name: testOneDB
maximum-pool-size: 15
max-lifetime: 180000
idle-timeout: 60000
connection-timeout: 20000
minimum-idle: 5
connection-test-query: SELECT 1
illust:
jdbc-url:

最低0.47元/天 解锁文章

700

被折叠的 条评论
为什么被折叠?



