數據源不能使用下划線 “_” 如
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>