spring boot 集成 mysql ,mybatisplus多数据源

1、需要的依赖,版本自行控制

cs 复制代码
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
</dependency>

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>

<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
</dependency>

2、配置文件

cs 复制代码
spring:
  datasource:
    dynamic:
      primary: master
      strict: false
      datasource:
        master:
          url: jdbc:mysql://xxx?useSSL=false&useUnicode=true&characterEncoding=utf8
          username: root
          password: pas
          driver-class-name: com.mysql.cj.jdbc.Driver
        two:
          url: jdbc:mysql://xxx?useSSL=false&useUnicode=true&characterEncoding=utf8
          username: root
          password: pas
          driver-class-name: com.mysql.cj.jdbc.Driver

3、使用方法,添加DS注解,值为配置的数据源名称

4、直接使用

相关推荐
Trouvaille ~6 分钟前
【MySQL】视图:虚拟表的妙用
数据库·mysql·adb·面试·数据处理·后端开发·视图
橙露11 分钟前
SpringBoot 全局异常处理:优雅封装统一返回格式
java·spring boot·后端
消失的旧时光-19431 小时前
Spring Boot 入门实战(二):用户注册接口设计(Controller + DTO + Validation)
java·spring boot·接口
亚空间仓鼠2 小时前
关系型数据库MySQL(二):高级特性
数据库·sql·mysql
A-Jie-Y2 小时前
JAVA框架-SpringBoot环境搭建指南
java·spring boot
亚空间仓鼠2 小时前
关系型数据库MySQL(五):Galara高可用
数据库·mysql
码界奇点2 小时前
基于Spring Boot的前后端分离商城系统设计与实现
java·spring boot·后端·java-ee·毕业设计·源代码管理
做时间的朋友。3 小时前
MySQL 8.0 窗口函数
android·数据库·mysql
试试勇气3 小时前
MySQL--库的操作
数据库·mysql
消失的旧时光-19433 小时前
Spring Boot 接口设计进阶:POST / PUT / DELETE 的本质区别与工程实践
spring boot·后端