From d75037fe9369567eb289f5ce2c4a9aaa59b62839 Mon Sep 17 00:00:00 2001 From: zyx <1029606625@qq.com> Date: Tue, 28 Feb 2023 12:56:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8Sharding-JDBC=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E8=AF=BB=E5=86=99=E5=88=86=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 9 +++++-- src/main/resources/application.yml | 39 +++++++++++++++++++++++++----- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index e96a1aa..250aec7 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,11 @@ org.springframework.boot spring-boot-starter-data-redis + + org.apache.shardingsphere + sharding-jdbc-spring-boot-starter + 4.1.1 + org.springframework.boot spring-boot-starter-test @@ -44,8 +49,8 @@ com.alibaba - druid-spring-boot-starter - 1.2.8 + druid + 1.2.12 org.projectlombok diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8f3166d..3db17a2 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,13 +1,40 @@ 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: redis: 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: # password: