MCPcopy Index your code
hub / github.com/chenlei2/spring-boot-mybatis-rw

github.com/chenlei2/spring-boot-mybatis-rw @1.0.1.release

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.0.1.release ↗ · + Follow
230 symbols 388 edges 24 files 25 documented · 11%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

spring-boot-mybatis-rw

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

Quick Start

介绍

此插件由以下2部分组成 - datasource:读写数据源的代理,支持一写多读,用户只需实现 org.spring.boot.mybatis.rw.starter.datasource.AbstractReadRoutingDataSource这个类,实现自己读数据源的负载均衡算法 - pulgin:mybatis插件实现读写路由

@Transactional(isolation = Isolation.SERIALIZABLE) 强制本事务都走写库,插件会把事务隔离级别修改为默认隔离级别

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:

    <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入侵,配置简单,非常方便老项目的迁移。 详细配置

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Method 201
Class 24
Interface 5

Languages

Java100%

Modules by API surface

spring-boot-mybatis-rw/spring-boot-mybatis-rw-sample/src/main/java/org/spring/boot/mybatis/rw/sample/mapper/StudentsExample.java55 symbols
spring-boot-mybatis-rw/mybatis-rw-sample-xml/src/main/java/org/spring/boot/mybatis/rw/sample/mapper/StudentsExample.java55 symbols
spring-boot-mybatis-rw/spring-boot-mybatis-rw-starter/src/main/java/org/spring/boot/mybatis/rw/starter/datasource/DataSourceProxy.java20 symbols
spring-boot-mybatis-rw/spring-boot-mybatis-rw-starter/src/main/java/org/spring/boot/mybatis/rw/starter/MybatisProperties.java18 symbols
spring-boot-mybatis-rw/spring-boot-mybatis-rw-sample/src/main/java/org/spring/boot/mybatis/rw/sample/mapper/StudentsMapper.java12 symbols
spring-boot-mybatis-rw/mybatis-rw-sample-xml/src/main/java/org/spring/boot/mybatis/rw/sample/mapper/StudentsMapper.java12 symbols
spring-boot-mybatis-rw/spring-boot-mybatis-rw-starter/src/main/java/org/spring/boot/mybatis/rw/starter/datasource/AbstractRWDataSourceRout.java10 symbols
spring-boot-mybatis-rw/spring-boot-mybatis-rw-starter/src/main/java/org/spring/boot/mybatis/rw/starter/MybatisAutoConfiguration.java9 symbols
spring-boot-mybatis-rw/spring-boot-mybatis-rw-starter/src/main/java/org/spring/boot/mybatis/rw/starter/pulgin/RWPlugin.java6 symbols
spring-boot-mybatis-rw/spring-boot-mybatis-rw-sample/src/main/java/org/spring/boot/mybatis/rw/sample/mapper/Students.java5 symbols
spring-boot-mybatis-rw/mybatis-rw-sample-xml/src/main/java/org/spring/boot/mybatis/rw/sample/mapper/Students.java5 symbols
spring-boot-mybatis-rw/spring-boot-mybatis-rw-starter/src/main/java/org/spring/boot/mybatis/rw/starter/datasource/UserDataSourceRout.java3 symbols

For agents

$ claude mcp add spring-boot-mybatis-rw \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page