routing-datasource-spring-boot-starter

An routing datasource for Spring Boot.

License

License

Categories

Categories

Spring Boot Container Microservices Data
GroupId

GroupId

com.blockpie
ArtifactId

ArtifactId

routing-datasource-spring-boot-starter
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

routing-datasource-spring-boot-starter
An routing datasource for Spring Boot.
Project URL

Project URL

https://github.com/blockpie/routing-datasource-spring-boot-starter
Project Organization

Project Organization

Blockpie Technology Co., Ltd.
Source Code Management

Source Code Management

https://github.com/blockpie/routing-datasource-spring-boot-starter.git

Download routing-datasource-spring-boot-starter

How to add to project

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

Dependencies

compile (3)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-jdbc jar
org.springframework.boot : spring-boot-starter-aop jar
com.alibaba : druid jar 1.1.14

Project Modules

There are no modules declared in this project.

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

com.blockpie

Blockpie

Sharing allows us to make progress together.

Versions

Version
1.0.0