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、直接使用

相关推荐
问道飞鱼2 小时前
【数据库知识】Mysql进阶-高可用MHA(Master High Availability)方案
数据库·mysql·adb·高可用·mha
tiging2 小时前
centos7.x下,使用宝塔进行主从复制的原理和实践
数据库·mysql·adb·主从复制
weixin_545019322 小时前
微信小程序智能商城系统(uniapp+Springboot后端+vue管理端)
spring boot·微信小程序·uni-app
一只fish2 小时前
MySQL 8.0 OCP 1Z0-908 题目解析(2)
数据库·mysql
一只码代码的章鱼3 小时前
Spring的 @Validate注解详细分析
前端·spring boot·算法
大学生小郑4 小时前
Go语言八股之Mysql基础详解
mysql·面试
Lw老王要学习4 小时前
Linux数据库篇、第一章_02_MySQL的使用增删改查
linux·运维·数据库·mysql·云计算·it
林下清风~5 小时前
MySQL——九、锁
数据库·mysql
程序员小杰@5 小时前
【MCP教程系列】SpringBoot 搭建基于 Spring AI 的 SSE 模式 MCP 服务
人工智能·spring boot·spring
程序员buddha5 小时前
Spring & Spring Boot 常用注解整理
java·spring boot·spring