Skip to content

开箱即用的基于 Spring Boot 和 MyBatis 的读写分离库

License

Notifications You must be signed in to change notification settings

jun1st/master-slave-datasource

Repository files navigation

master-slave-datasource

开箱即用的读写分离插件,在 Spring Boot里,通过使用 Spring 的 AutoConfigure 机制,自动注入 DataSource, 实现读写分析。

事务都走 master 数据库 单条 SQL 语句根据语句内容判断是走主数据库,还是只读数据库

<dependency>
    <groupId>com.github.jun1st</groupId>
    <artifactId>master-slave-datasource-starter</artifactId>
    <version>0.5.0</version>
</dependency>

配置数据库

  spring:
    master-slave: true
    data-source:
      master-slave:
      mybatis: true
      hikari:
        connection-init-sql: SET NAMES 'utf8mb4'
      master:
        url: jdbc:mysql://localhost:3306/database-master
        username: root
        password: p@ssw0rd
        driver-class-name: com.mysql.jdbc.Driver
      slave:
        one:
          url: jdbc:mysql://localhost:3306/database-slave1
          username: root
          password: p@ssw0rd
          driver-class-name: com.mysql.jdbc.Driver
        two:
          url: jdbc:mysql://localhost:3306/database-slave2
          username: root
          password: p@ssw0rd
          driver-class-name: com.mysql.jdbc.Driver

更新日志

2019-07-17 update lombok, 支持jdk 11

About

开箱即用的基于 Spring Boot 和 MyBatis 的读写分离库

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages