强制路由实战
实战代码示例: https://gitee.com/ixinglan/mysql-demo.git
sharding-jdbc-demo: 详见README.md 介绍
我们以city表示例
- 新建 application-hint-database.yml, 并将主配置文件active改为hint-database
# datasource
spring:
shardingsphere:
datasource:
names: ds0,ds1
ds0:
type: com.zaxxer.hikari.HikariDataSource
driver-class: com.mysql.jdbc.Driver
jdbc-url: jdbc:mysql://localhost:3306/sharding-demo1
username: root
password: 123456
ds1:
type: com.zaxxer.hikari.HikariDataSource
driver-class: com.mysql.jdbc.Driver
jdbc-url: jdbc:mysql://localhost:3306/sharding-demo2
username: root
password: 123456
# sharding-database
sharding:
tables:
city:
databaseStrategy:
hint:
algorithmClassName: com.hint.MyHintShardingAlgorithm
- 创建 MyHintShardingAlgorithm 类实现HintShardingAlgorithm
- 测试方法 TestHintAlgorithm: test1