<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          spring-boot-mybatis-rw讀寫(xiě)分離插件

          聯(lián)合創(chuàng)作 · 2023-09-28 12:04

          spring-boot-mybatis-rw

          基于mybatis,springboot開(kāi)箱即用的讀寫(xiě)分離插件

          Quick Start

          介紹

          此插件由以下2部分組成

          • datasource:讀寫(xiě)數(shù)據(jù)源的代理,支持一寫(xiě)多讀,用戶只需實(shí)現(xiàn) org.spring.boot.mybatis.rw.starter.datasource.AbstractReadRoutingDataSource這個(gè)類(lèi),實(shí)現(xiàn)自己讀數(shù)據(jù)源的負(fù)載均衡算法

          • pulgin:mybatis插件實(shí)現(xiàn)讀寫(xiě)路由

          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:

          <!--簡(jiǎn)單的一個(gè)master和多個(gè)slaver 讀寫(xiě)分離的數(shù)據(jù)源 -->
          	<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>

          總結(jié)

          只需將數(shù)據(jù)源和事務(wù)工廠注入到sqlSessionFactory中,其他配置不變,便實(shí)現(xiàn)讀寫(xiě)分離,對(duì)代碼0入侵,配置簡(jiǎn)單,非常方便老項(xiàng)目的遷移。 詳細(xì)配置

          瀏覽 19
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  大香蕉欧美伊人 | 欧洲亚洲视频在线 | 国产一级操逼大黄视频 | 操逼高潮视频 | 北条麻妃在线视频 |