{"id":13694847,"url":"https://github.com/chenlei2/spring-boot-mybatis-rw","last_synced_at":"2025-05-03T04:31:01.607Z","repository":{"id":52638522,"uuid":"62493095","full_name":"chenlei2/spring-boot-mybatis-rw","owner":"chenlei2","description":"基于mybatis，springboot开箱即用的读写分离插件","archived":false,"fork":false,"pushed_at":"2021-04-22T17:34:21.000Z","size":161,"stargazers_count":339,"open_issues_count":10,"forks_count":151,"subscribers_count":45,"default_branch":"master","last_synced_at":"2025-03-16T18:56:30.869Z","etag":null,"topics":["datasource","java","mybatis","read-write-separation","read-write-splitting","spring-boot-mybatis","transaction"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chenlei2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-03T11:12:02.000Z","updated_at":"2025-03-16T11:07:41.000Z","dependencies_parsed_at":"2022-08-21T23:20:56.009Z","dependency_job_id":null,"html_url":"https://github.com/chenlei2/spring-boot-mybatis-rw","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenlei2%2Fspring-boot-mybatis-rw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenlei2%2Fspring-boot-mybatis-rw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenlei2%2Fspring-boot-mybatis-rw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chenlei2%2Fspring-boot-mybatis-rw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chenlei2","download_url":"https://codeload.github.com/chenlei2/spring-boot-mybatis-rw/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251389349,"owners_count":21581780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datasource","java","mybatis","read-write-separation","read-write-splitting","spring-boot-mybatis","transaction"],"created_at":"2024-08-02T17:01:44.988Z","updated_at":"2025-05-03T04:31:00.748Z","avatar_url":"https://github.com/chenlei2.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":"# spring-boot-mybatis-rw\n基于mybatis，springboot开箱即用的读写分离插件\n\n# Quick Start\nMaven dependency\n---\n```\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.github.chenlei2\u003c/groupId\u003e\n  \u003cartifactId\u003espring-boot-mybatis-rw-starter\u003c/artifactId\u003e\n  \u003cversion\u003e0.0.1.releases\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n介绍\n---\n此插件由以下2部分组成\n- datasource：读写数据源的代理，支持一写多读，用户只需实现 com.github.chenlei2.springboot.mybatis.rw.starter.datasource.AbstractReadRoutingDataSource这个类，实现自己读数据源的负载均衡算法，默认实现com.github.chenlei2.springboot.mybatis.rw.starter.datasource.impl.RoundRobinRWDataSourceRout\n- pulgin：mybatis插件实现读写路由\n\n\n@Transactional(isolation = Isolation.SERIALIZABLE) 强制本事务都走写库，插件会把事务隔离级别修改为默认隔离级别\n\nspring-boot 配置\n---\n```\nspring.mybatis.rw.readDataSources[0].url=jdbc:MySql://localhost:3306/test?characterEncoding=UTF-8\nspring.mybatis.rw.readDataSources[0].driverClassName=com.mysql.jdbc.Driver\nspring.mybatis.rw.readDataSources[0].username=root\nspring.mybatis.rw.readDataSources[0].password=123456\nspring.mybatis.rw.readDataSources[1].url=jdbc:MySql://localhost:3306/test?characterEncoding=UTF-8\nspring.mybatis.rw.readDataSources[1].driverClassName=com.mysql.jdbc.Driver\nspring.mybatis.rw.readDataSources[1].username=root\nspring.mybatis.rw.readDataSources[1].password=123456\n\nspring.mybatis.rw.writeDataSource.url=jdbc:MySql://localhost:3306/chenlei?characterEncoding=UTF-8\nspring.mybatis.rw.writeDataSource.driverClassName=com.mysql.jdbc.Driver\nspring.mybatis.rw.writeDataSource.username=root\nspring.mybatis.rw.writeDataSource.password=123456\n``` \n\nXML配置\n---\n- datasource：\n```\n\u003c!--简单的一个master和多个slaver 读写分离的数据源 --\u003e\n\t\u003cbean id=\"roundRobinRWDataSourceRout\"\n\t    class=\"com.github.chenlei2.springboot.mybatis.rw.starter.datasource.impl.RoundRobinRWDataSourceRout\"\u003e\n\t    \u003cproperty name=\"writeDataSource\" ref=\"writeDS\"/\u003e\n\t    \u003cproperty name=\"readDataSoures\"\u003e\n\t        \u003clist\u003e\n\t            \u003cref bean=\"readDS\"/\u003e\n\t            \u003cref bean=\"readDS\"/\u003e\n\t            \u003cref bean=\"readDS\"/\u003e\n\t        \u003c/list\u003e\n\t    \u003c/property\u003e\n\t\u003c/bean\u003e\n\t\u003cbean id=\"dataSource\" class=\"com.github.chenlei2.springboot.mybatis.rw.starter.datasource.DataSourceProxy\"\u003e\n\t\t\u003cconstructor-arg ref=\"roundRobinRWDataSourceRout\"/\u003e\n\t\u003c/bean\u003e\n``` \n\n总结\n---\n只需替换数据源，其他配置不变，便实现读写分离，对代码0入侵，配置简单，非常方便老项目的迁移。\n[详细配置](https://github.com/chenlei2/spring-boot-mybatis-rw/blob/master/spring-boot-mybatis-rw/mybatis-rw-sample-xml/src/main/resources/spring-mybatis.xml)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenlei2%2Fspring-boot-mybatis-rw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchenlei2%2Fspring-boot-mybatis-rw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchenlei2%2Fspring-boot-mybatis-rw/lists"}