读写分离插件 spring-boot-mybatis-rw

spring-boot-mybatis-rw

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

Quick Start

Java

介绍

此插件由以下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-8spring.mybatis.rw.readDataSources[0].driverClassName=com.mysql.jdbc.Driver

spring.mybatis.rw.readDataSources[0].username=root

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

spring.mybatis.rw.readDataSources[1].username=root

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

spring.mybatis.rw.writeDataSource.username=root

spring.mybatis.rw.writeDataSource.password=123456

XML配置

datasource:


class="org.spring.boot.mybatis.rw.starter.datasource.impl.RoundRobinRWRoutingDataSourceProxy">

总结

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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,310评论 6 342
  • 一、Spring Boot 依赖管理   通过InteIIij IDEA创建Spring Boot项目,会发现在项...
    AaronSimon阅读 1,408评论 0 5
  • 佛洛里达的湖光天色,和窗前的春色,为什么要走远,幸福就在眼前……
    Heatheryang阅读 462评论 0 4
  • 一、什么是YTKNetwork YTKNetwork是一个基于AFNetworking的网络层封装。 二、包括那几...
    Bo_cake阅读 2,496评论 0 1

友情链接更多精彩内容