Spring Boot 整合 SardingSphere (单表访问以及分库分表)
Tips:
- 其他代码 链接:https://www.cnblogs.com/yi1036943655/p/15700170.html
- 在实际的项目里,不可能项目只有分库分表的表,肯定是带有不分库分表的表,当我学习SardingSphere的时候,我就在想这东西怎么配置,查阅过各种文章。总结就是在添加个数据源,无需额外配置。把不分库不分表的表,都放到这个数据源里。
- 写的不一定正确,大佬勿喷,如果有更高效的方法,请指教
application.properties
spring.shardingsphere.datasource.names=sharding,sharding0,sharding1 # 第零个数据库 spring.shardingsphere.datasource.sharding.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.sharding.driver-class-name=com.mysql.cj.jdbc.Driver spring.shardingsphere.datasource.sharding.jdbc-url=jdbc:mysql://localhost:3306/sharding0?serverTimezone=GMT%2B8&useSSL=false spring.shardingsphere.datasource.sharding.username=root spring.shardingsphere.datasource.sharding.password=root # 第一个数据库 spring.shardingsphere.datasource.sharding0.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.sharding0.driver-class-name=com.mysql.cj.jdbc.Driver spring.shardingsphere.datasource.sharding0.jdbc-url=jdbc:mysql://localhost:3306/sharding0?serverTimezone=GMT%2B8&useSSL=false spring.shardingsphere.datasource.sharding0.username=root spring.shardingsphere.datasource.sharding0.password=root # 第二个数据库 spring.shardingsphere.datasource.sharding1.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.sharding1.driver-class-name=com.mysql.cj.jdbc.Driver spring.shardingsphere.datasource.sharding1.jdbc-url=jdbc:mysql://localhost:3306/sharding1?serverTimezone=GMT%2B8&useSSL=false spring.shardingsphere.datasource.sharding1.username=root spring.shardingsphere.datasource.sharding1.password=root