sharding-jdbc简介
现已更名为: sharding-sphere,官方网址如下 https://shardingsphere.apache.org/document/current/cn/overview/ 简单来说,最主要的可以做以下事情: 1.数据库读写分离 2.数据库分库分表 3.分布式事务 在今天的DEMO中, 我们一起来用shard-sphere来做数据库的读写分离 主要需要以下几步: 1.准备主从的数据库, 参考文章: https://www.javastudy.cloud/articles/2019/11/14/1573693221155.html 2.在springboot工程中,引入相应的mybatis和shard-spere的依赖 3.编写测试类
springboot+sharding-jdbc+HikariCP+mybatis做读写分离
添加依赖
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.1' runtimeOnly 'mysql:mysql-connector-java' // 这里多了一个shardingsphere的依赖 compile group: 'org.apache.shardingsphere', name: 'sharding-jdbc-spring-boot-starter', version: '4.0.0-RC3'
添加springboot的配置
# 这里我们有一主一从 spring.shardingsphere.datasource.names=master,slave0 # 主库的配置 spring.shardingsphere.datasource.master.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.master.driver-class-name=com.mysql.cj.jdbc.Driver spring.shardingsphere.datasource.master.jdbcUrl=jdbc:mysql://localhost:33309/tools spring.shardingsphere.datasource.master.username=root spring.shardingsphere.datasource.master.password=javastudy # 从库的配置 spring.shardingsphere.datasource.slave0.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.slave0.driver-class-name=com.mysql.cj.jdbc.Driver spring.shardingsphere.datasource.slave0.jdbcUrl=jdbc:mysql://localhost:33308/tools spring.shardingsphere.datasource.slave0.username=root spring.shardingsphere.datasource.slave0.password=javastudy # sharding-jdbc本身的一些配置 spring.shardingsphere.masterslave.name=ms spring.shardingsphere.masterslave.master-data-source-name=master spring.shardingsphere.masterslave.slave-data-source-names=slave0 spring.shardingsphere.props.sql.show=true
这里要注意, 主库和从库配置的第一行, datasource.master.type 这里, 要写HikariDataSource, 这样就可以使用HikariCP了 然后平常hikariCP和Mybatis的配置照常配置就可以了, 但是不在需要spring.datasource.url,spring.datasource.username
这些配置了
编写测试类
mybatis的mapper还是按原来的写法写, 然后我们使用autowire进行注入
@Autowired private ArticleMapper articleMapper; @Test public void testDataSource(){ List<ArticleDO> articleDOS = articleMapper.listArticles(new ArticleQC()); System.out.println(articleDOS); }
运行单元测试,可通过日志看出使用了hikariCP+sharding-jdbc
相关推荐
springboot集成shardingJDBC实现读写分离demo工程,亲测可用 使用方式见博客:https://maoqizhi.blog.csdn.net/article/details/123149268?spm=1001.2014.3001.5502
sjdbc-read-write-springboot:Spring Boot版 Sharding JDBC 读写分离示列 sjdbc-db-sharding-springboot:Spring Boot版 Sharding JDBC 垂直拆分(不同的表在不同的库中) sjdbc-db-read-write-sharding-...
使用sharding-jdbc快速实现自动读写分离-demo源码!
sharding-jdbc 读写分离
主要介绍了详解Spring Boot中整合Sharding-JDBC读写分离示例,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
1:多租户系统集成 2:集成shardingjdbc分库分表 3:集成shardingjdbc读写分离 4:集成人大金仓数据库 5:重写了JPA-saveandflush方法 6:修复了JPA更新数据为null的问题 7:解压后导入idea,创建数据库即可运行测试
Sharding-JDBC教程:Spring Boot整合Sharding-JDBC实现分库分表+读写分离
SpringBoot、Mybaits-Plus、Druid
Sharding-JDBC实现读写分离demo
Sharding-JDBC教程:Spring Boot整合Sharding-JDBC实现读写分离
ShardingJDBC通过数据分片和读写分离,使Java应用能透明地访问分库分表的多个数据源。它在JDBC层提供服务,无需额外部署,兼容各种ORM框架。与ShardingProxy不同,ShardingJDBC在客户端执行分库分表逻辑,提供...
1、基于yml 配置方式 ,实现springBoot+sharding-jdbc+mybatis-plus 实现分库分表,读写分离,以及全局表,子表的配置。 2、实现mybatis-plus 整合到springboot 详细使用请看 测试用例
2、sharding-jdbc (1)、实现多种模式的读写分离 (2)、支持事务 (3)、配置中心化 (4)、存储过程不能正常解析 ———————————————— 版权声明:本文为CSDN博主「毛豆有毛没豆」的原创文章,...
Sharding-JDBC完整的实现了分库分表,读写分离和分布式主键功能,并初步实现了柔性事务。从2016年开源至今,在经历了整体架构的数次精炼以及稳定性打磨后,如今它已积累了足够的底蕴,相信可以成为开发者选择技术...
Sharding Sphere的所有使用过程,具体内容如下: ...5、使用使用 Sharding-JDBC 读写分离 三、Sharding-Proxy 1、什么是 Sharding-Proxy 2、使用 Sharding-Proxy 分库分表 3、使用 Sharding-Proxy 读写分离
采⽤Sharding-JDBC实现订单表的 分库分表 和 读写分离,搭建 两套一主二从 主从集群
数据库(分库分表、读写分离)
sharding-jdbc-orchestration-4.1.1.jar sharding-jdbc-core-4.1.1.jar 参考下下面链接,更改源码 https://github.com/apache/shardingsphere/pull/6002/files/c191c9571ab5a2e9e6d3f0c0f84c8bb6cd36d851
Sharding-JDBC集分库分表、读写分离、分布式主键、柔性事务和数据治理与一身,提供一站式的解决分布式关系型数据库的解决方案。
前端:原生 HTML + 渐进式 Vue + Axios + Element UI 后端:Spring Boot + SSM + MyBatis Plus + Spring Cache + Redis + Sharding JDBC 读写分离 + 短信 SDK + Lombok 部署:前后端不分离 - 不懂运行,下载完可以...