spring.main.allow-bean-definition-overriding = true
#
mybatis.configuration.map-underscore-to-camel-case = true
#sharding-jdbc分片规则配置
#数据源
#sharding-jdbc分片规则配置
#定义数据源
spring.shardingsphere.datasource.names = m1
spring.shardingsphere.datasource.m1.type = com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.m1.driver-class-name = com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.m1.url = jdbc:mysql://localhost:3306/article1?useUnicode=true
spring.shardingsphere.datasource.m1.username = article1
spring.shardingsphere.datasource.m1.password = article1
# 指定t_order表的数据分布情况,配置数据节点 m1.t_order_1,m1.t_order_2
spring.shardingsphere.sharding.tables.auto_article.actual-data-nodes = m1.auto_article_$->{1..2}
# 指定t_order表的主键生成策略为SNOWFLAKE
spring.shardingsphere.sharding.tables.auto_article.key-generator.column=id
spring.shardingsphere.sharding.tables.auto_article.key-generator.type=SNOWFLAKE
# 指定t_order表的分片策略,分片策略包括分片键和分片算法
spring.shardingsphere.sharding.tables.auto_article.table-strategy.inline.sharding-column = id
spring.shardingsphere.sharding.tables.auto_article.table-strategy.inline.algorithm-expression = auto_article_$->{id % 2 + 1}
依赖
参考:https://blog.csdn.net/bochuangli/article/details/123014331
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-boot-starter</artifactId>
<version>${sharding-jdbc-version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>sharding-jdbc-spring-namespace</artifactId>
<version>${sharding-jdbc-version}</version>
</dependency>
这篇文章还没有评论