master-slave-datasource-starter

mysql master slave datasource support for spring boot starter

License

License

Categories

Categories

Data
GroupId

GroupId

com.github.jun1st
ArtifactId

ArtifactId

master-slave-datasource-starter
Last Version

Last Version

0.5.0
Release Date

Release Date

Type

Type

jar
Description

Description

master-slave-datasource-starter
mysql master slave datasource support for spring boot starter
Source Code Management

Source Code Management

https://github.com/jun1st/master-slave-datasource.git

Download master-slave-datasource-starter

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.jun1st/master-slave-datasource-starter/ -->
<dependency>
    <groupId>com.github.jun1st</groupId>
    <artifactId>master-slave-datasource-starter</artifactId>
    <version>0.5.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.jun1st/master-slave-datasource-starter/
implementation 'com.github.jun1st:master-slave-datasource-starter:0.5.0'
// https://jarcasting.com/artifacts/com.github.jun1st/master-slave-datasource-starter/
implementation ("com.github.jun1st:master-slave-datasource-starter:0.5.0")
'com.github.jun1st:master-slave-datasource-starter:jar:0.5.0'
<dependency org="com.github.jun1st" name="master-slave-datasource-starter" rev="0.5.0">
  <artifact name="master-slave-datasource-starter" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.jun1st', module='master-slave-datasource-starter', version='0.5.0')
)
libraryDependencies += "com.github.jun1st" % "master-slave-datasource-starter" % "0.5.0"
[com.github.jun1st/master-slave-datasource-starter "0.5.0"]

Dependencies

compile (5)

Group / Artifact Type Version
org.springframework.boot : spring-boot-autoconfigure jar 2.0.3.RELEASE
org.springframework.boot : spring-boot-starter-aop jar 2.0.3.RELEASE
org.projectlombok : lombok Optional jar 1.18.8
org.springframework.boot : spring-boot-starter-jdbc jar 2.0.3.RELEASE
org.mybatis.spring.boot : mybatis-spring-boot-starter jar 1.3.2

Project Modules

There are no modules declared in this project.

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

Versions

Version
0.5.0
0.4.1
0.4.0
0.2.0