Springboot2.x + sharding-jdbc + 分库(不分表)

数据源不能使用下划线 “_”  如 

member0 不能写为 member_0 ,否刚会报错

sharding-jdbc 配置 ,不需要java配置

# 数据源
sharding:
  jdbc:
    config:
      sharding:
        default-data-source-name: member1
        default-database-strategy:
          inline:
            sharding-column: business_id
            algorithm-expression: member${business_id}
datasource: names: member0,member1 #商家0的DB member0: type: com.alibaba.druid.pool.DruidDataSource url: jdbc:mysql:
//mysql1:3306/ybf_member0?useUnicode=true&characterEncoding=utf8&useSSL=true&allowMultiQueries=true&verifyServerCertificate=false username: root password: 123456 member1: type: com.alibaba.druid.pool.DruidDataSource url: jdbc:mysql://mysql1:3306/ybf_member1?useUnicode=true&characterEncoding=utf8&useSSL=true&allowMultiQueries=true&verifyServerCertificate=false username: root password: 123456

 

 

maven依赖

<!-- https://mvnrepository.com/artifact/io.shardingsphere/sharding-core -->
        <dependency>
            <groupId>io.shardingsphere</groupId>
            <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>io.shardingsphere</groupId>
            <artifactId>sharding-jdbc-spring-namespace</artifactId>
            <version>3.0.0</version>
        </dependency>

 

posted @ 2019-06-04 17:03  csdn代下载微robnote  阅读(2175)  评论(4编辑  收藏  举报