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
  • 相关阅读:
    Jmeter性能测试 入门
    线程模型——什么是线程池、以及怎样正确地配置线程池
    在Spring Bean的生命周期中各方法的执行顺序
    @Autowired @Qualifier
    @Autowired还可以注入List和Map
    springcloud ribbon的 @LoadBalanced注解
    CAS实现SSO 单点登录
    Docker 概念-2
    你的JavaBean是否真的需要实现Serializable
    基于django的会议室预订系统
  • 原文地址:https://www.cnblogs.com/yi1036943655/p/15734158.html
Copyright © 2011-2022 走看看