使用Sharding-JDBC实现读写分离
This commit is contained in:
parent
a3cd3c85b2
commit
d75037fe93
9
pom.xml
9
pom.xml
@ -32,6 +32,11 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.shardingsphere</groupId>
|
||||||
|
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
|
||||||
|
<version>4.1.1</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
@ -44,8 +49,8 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>druid-spring-boot-starter</artifactId>
|
<artifactId>druid</artifactId>
|
||||||
<version>1.2.8</version>
|
<version>1.2.12</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
@ -1,13 +1,40 @@
|
|||||||
spring:
|
spring:
|
||||||
|
shardingsphere:
|
||||||
|
datasource:
|
||||||
|
names:
|
||||||
|
master,slave
|
||||||
|
# 主数据源
|
||||||
|
master:
|
||||||
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
# url:
|
||||||
|
username: root
|
||||||
|
# password:
|
||||||
|
# 从数据源
|
||||||
|
slave:
|
||||||
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
# url:
|
||||||
|
username: root
|
||||||
|
# password:
|
||||||
|
masterslave:
|
||||||
|
# 读写分离配置
|
||||||
|
# 从库负载均衡的策略,此处是轮询
|
||||||
|
load-balance-algorithm-type: round_robin
|
||||||
|
# 最终的数据源名称
|
||||||
|
name: dataSource
|
||||||
|
# 主库数据源名称
|
||||||
|
master-data-source-name: master
|
||||||
|
# 从库数据源名称列表,多个逗号分隔
|
||||||
|
slave-data-source-names: slave
|
||||||
|
props:
|
||||||
|
sql:
|
||||||
|
show: true #开启SQL显示,默认false
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
cache:
|
cache:
|
||||||
redis:
|
redis:
|
||||||
time-to-live: 1800000
|
time-to-live: 1800000
|
||||||
datasource:
|
|
||||||
druid:
|
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
||||||
url: jdbc:mysql://localhost:3306/reggie?serverTimezone=Asia/Shanghai
|
|
||||||
username: root
|
|
||||||
# password:
|
|
||||||
# redis:
|
# redis:
|
||||||
# password:
|
# password:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user