其他分享
首页 > 其他分享> > SpringBoot之多数据源动态切换数据源

SpringBoot之多数据源动态切换数据源

作者:互联网

两个数据库

1,依赖

  

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

2,yml

spring:
  datasource:
    dynamic:
      #primary: master #设置默认的数据源或者数据源组,默认值即为master
      #strict: false #设置严格模式,默认false不启动. 启动后在未匹配到指定数据源时候会抛出异常,不启动则使用默认数据源.
      #datasource:
      master:
        url: jdbc:mysql://ip+端口/woke_cloud_social?characterEncoding=UTF-8&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=CTT&tinyInt1isBit=false
        username: 
        password: 
        #driver-class-name: com.mysql.jdbc.Driver
      slave:
        slave_1:
          url: jdbc:mysql://ip+端口/woke_cloud_property?characterEncoding=UTF-8&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=CTT&tinyInt1isBit=false
          username: 
          password: 
          #driver-class-name: com.mysql.jdbc.Driver

3,在mapper加从节点的注解

 

 

  

标签:jdbc,false,SpringBoot,数据源,master,datasource,mysql,之多
来源: https://www.cnblogs.com/yangxiaoli/p/13985696.html