当前位置: 首页 > 软件库 > 程序开发 > 常用工具包 >

spring-boot-mybatis-rw

读写分离插件
授权协议 未知
开发语言 Java
所属分类 程序开发、 常用工具包
软件类型 开源软件
地区 国产
投 递 者 梁丘洲
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

spring-boot-mybatis-rw

基于mybatis,springboot开箱即用的读写分离插件

Quick Start

介绍

此插件由以下2部分组成

  • datasource:读写数据源的代理,支持一写多读,用户只需实现 org.spring.boot.mybatis.rw.starter.datasource.AbstractReadRoutingDataSource这个类,实现自己读数据源的负载均衡算法

  • pulgin:mybatis插件实现读写路由

spring-boot 配置

spring.mybatis.rw.readDataSources[0].url=jdbc:MySql://localhost:3306/test?characterEncoding=UTF-8
spring.mybatis.rw.readDataSources[0].driverClassName=com.mysql.jdbc.Driver
spring.mybatis.rw.readDataSources[0].username=root
spring.mybatis.rw.readDataSources[0].password=123456
spring.mybatis.rw.readDataSources[1].url=jdbc:MySql://localhost:3306/test?characterEncoding=UTF-8
spring.mybatis.rw.readDataSources[1].driverClassName=com.mysql.jdbc.Driver
spring.mybatis.rw.readDataSources[1].username=root
spring.mybatis.rw.readDataSources[1].password=123456

spring.mybatis.rw.writeDataSource.url=jdbc:MySql://localhost:3306/chenlei?characterEncoding=UTF-8
spring.mybatis.rw.writeDataSource.driverClassName=com.mysql.jdbc.Driver
spring.mybatis.rw.writeDataSource.username=root
spring.mybatis.rw.writeDataSource.password=123456

XML配置

  • datasource:

<!--简单的一个master和多个slaver 读写分离的数据源 -->
	<bean id="dataSource" 
	    class="org.spring.boot.mybatis.rw.starter.datasource.impl.RoundRobinRWRoutingDataSourceProxy">
	    <property name="writeDataSource" ref="writeDS"/>
	    <property name="readDataSoures">
	        <list>
	            <ref bean="readDS"/>
	            <ref bean="readDS"/>
	            <ref bean="readDS"/>
	        </list>
	    </property>
	</bean>

总结

只需将数据源和事务工厂注入到sqlSessionFactory中,其他配置不变,便实现读写分离,对代码0入侵,配置简单,非常方便老项目的迁移。 详细配置

  • 1. 创建一个springboot应用 1.1 创建   springboot应用没有相应的archetype,不能通过mvn generate:archetype创建,一般有两种方式创建一个springboot应用: 访问 https://start.spring.io/,选择Web依赖,点击Generate Project 创建一个springboot应用。 通过IDEA:File -> Ne

  • 本文介绍了springboot如何集成elasticsearch-sql+mybatis 大家好!ElasticSearch(下面用es作为缩减)作为开源界搜索和数据分析的宠儿,受到了很多公司的青睐,无论是查询速度,还是扩展性,容错性都是很不错的,而且配合官方的logstash和kibana,以及filebeat,更是如虎添翼,但是es的transport client的api是解析非常困难,而且

  • 自己封装了一个读写分离的 Starter,可以配置任意多个数据源,使用 Hikari 连接池(暂不支持其他连接池)。 GitHub:rw-separate-spring-boot-starter 代码已上传到 Maven 中央仓库,可以直接使用: <dependency> <groupId>top.cloudli</groupId> <artifactId>rw-separate-

  • 1、数据源配置 spring.datasource.master.driver-class-name = com.mysql.jdbc.Driver spring.datasource.master.filters = wall,stat spring.datasource.master.initial-size = 50 spring.datasource.master.max-active =

  •    需求:对于一些统计类型的接口,部分是运营看的,实时性不太强,但是查询特别的复杂,查主库?不好,万一锁库呢。查从库。对直接查从库就好了。    对于老项目,有没有直接配一下从库就直接走从库的啊?当然有了。一个后台给运营配置数据和查询统计的后台管理系统,有好几个查询都很慢,假如走主库的话,怕会影响前端接口的调用。所以,直接走从库。很好用,强烈推荐。    git如下             ht

 相关资料
  • 从1.r.58开始, 内置读写分离支持 ioc js形式的配置 NutDaoRunner新增了slaveDataSource属性 dataSource : { // master数据源 }, slaveDataSource : { // slave数据源,负责读 }, dao : { type : "org.

  • 在ReplicaSet副本集环境中,可以通过bugu-mongo设置读写分离。 默认情况下,写操作、读操作,全部都是在Primary上进行,如下图,这可能会导致Primary的负载比较高。 为了降低Primary的负载,可以设置成允许从Secondary读取数据,如下图: 慎重考虑 读写分离,看上去很美,但实际有如下问题需要考虑: 一般情况下,并不建议对ReplicaSet进行读写分离。因为,对于

  • ReplicaLoadBalanceAlgorithm SPI 名称 详细说明 ReplicaLoadBalanceAlgorithm 读库负载均衡算法 已知实现类 详细说明 RoundRobinReplicaLoadBalanceAlgorithm 基于轮询的读库负载均衡算法 RandomReplicaLoadBalanceAlgorithm 基于随机的读库负载均衡算法

  • 配置项说明 命名空间:http://shardingsphere.apache.org/schema/shardingsphere/readwrite-splitting/readwrite-splitting-5.0.0.xsd <readwrite-splitting:rule /> 名称 类型 说明 id 属性 Spring Bean Id data-source-rule (+) 标签 读

  • 配置项说明 spring.shardingsphere.datasource.names= # 省略数据源配置,请参考使用手册 spring.shardingsphere.rules.readwrite-splitting.data-sources.<readwrite-splitting-data-source-name>.write-data-source-name= # 写数据源名称 sp

  • 配置项说明 dataSources: # 省略数据源配置,请参考使用手册 rules: - !READWRITE_SPLITTING dataSources: <data-source-name> (+): # 读写分离逻辑数据源名称 writeDataSourceName: # 写库数据源名称 readDataSourceNames: -