Skip to content

Routing datasource for Spring Boot 路由数据源/主从分离/从库切换

License

Notifications You must be signed in to change notification settings

blockpie/routing-datasource-spring-boot-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

routing-datasource-spring-boot-starter

Maven Central GitHub release License

Introduction 简介

  • Routing datasource for Spring Boot 结合 SpringBoot 使用的路由数据源
  • Master-slave splitting 主从分离
  • Switching slave datasource random or balanced 从库随机或均衡切换

How to use 使用方法

1. Import maven dependency (引入 maven 依赖)

<dependency>
  <groupId>com.blockpie</groupId>
  <artifactId>routing-datasource-spring-boot-starter</artifactId>
  <version>${latest.release.version}</version>
</dependency>

Note: Please change the ${latest.release.version} to the actual version

注意: 请修改 ${latest.release.version} 为实际版本

2. Configure rule configuration (配置数据源)

routing-datasource:
  data-source-map:
    test1:
      description: test database 1
      strategy: random
      list:
        - driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://127.0.0.1:3306/test1_master
          username: root
          password: pass
          type: com.alibaba.druid.pool.DruidDataSource
        - driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://127.0.0.1:3306/test1_slave1
          username: root
          password: pass
          type: com.zaxxer.hikari.HikariDataSource
        - driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://127.0.0.1:3306/test1_slave2
          username: root
          password: pass
    test2:
      description: test database 2
      strategy: balance
      list:
        - driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://127.0.0.1:3306/test2
          username: root
          password: pass

list[0] is the master, others are the slaves

数据源的第一项为主数据源, 其余的为从数据源

strategy: random / balance (default)

strategy 支持 random / balance 两个选项, 默认为 balance

About

Routing datasource for Spring Boot 路由数据源/主从分离/从库切换

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages