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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM