zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    Vue.js入门(3)TypeScript
    Dapper源码学习
    .Net中手动实现AOP
    .Net面向对象(OOP)
    Redis实战(18)Redis位图巧用,节约内存
    .Net深拷贝浅拷贝
    .NET面试题系列(22)字符串暂存池(缓冲池)
    .NET面试题系列(二十一)C#中Equals和==的比较
    C# 8.0
    C# 7.0
  • 原文地址:https://www.cnblogs.com/yi1036943655/p/15734158.html
Copyright © 2011-2022 走看看