shardingsphere3.0.0读写分离配置

基于spring-boot项目,在使用shardingsphere3.0.0进行读写分离配置时,参考官网配置示例有点出入,查看源码找到对应的路径,配置如下
pom.xml

<dependency>
    <groupId>io.shardingspheregroupId>
    <artifactId>sharding-jdbc-spring-boot-starterartifactId>
    <version>3.0.0version>
dependency>
<dependency>
    <groupId>io.shardingspheregroupId>
    <artifactId>sharding-jdbc-spring-namespaceartifactId>
    <version>3.0.0version>
dependency>

application.yml

sharding:
  jdbc:
    datasource:
      names: master,slave0
      master:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://192.168.0.11:3306/db_test?useSSL=false&characterEncoding=utf-8
        username: root
        password: 123456
      slave0:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.jdbc.Driver
        url: jdbc:mysql://192.168.0.12:3306/db_test?useSSL=false&characterEncoding=utf-8
        username: root
        password: 123456
    config:
      masterslave:
        load-balance-algorithm-type: round_robin
        name: ms
        master-data-source-name: master
        slave-data-source-names: slave0
        props:
          sql:
            show:
              true

验证

2019-04-22 11:17:02.875  INFO 60289 --- [ost-startStop-1] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} inited
2019-04-22 11:17:03.242  INFO 60289 --- [ost-startStop-1] com.alibaba.druid.pool.DruidDataSource   : {dataSource-2} inited
...
2019-04-22 11:17:21.939  INFO 60289 --- [-192.168.224.93] Sharding-Sphere-SQL                      : Rule Type: master-slave
2019-04-22 11:17:21.939  INFO 60289 --- [-192.168.224.93] Sharding-Sphere-SQL                      : SQL: /* ping */ SELECT 1 ::: DataSources: slave0
  1. 两个dataSoruce inited
  2. 打印sql路由信息

你可能感兴趣的:(shardingsphere)