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