最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MyBatis-Plus實(shí)現(xiàn)多數(shù)據(jù)源的示例代碼

 更新時(shí)間:2020年11月15日 10:58:00   作者:youcongtech  
這篇文章主要介紹了MyBatis-Plus實(shí)現(xiàn)多數(shù)據(jù)源的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

多數(shù)據(jù)源的目的在于一個(gè)代碼模塊可調(diào)用多個(gè)數(shù)據(jù)庫的數(shù)據(jù)進(jìn)行某些業(yè)務(wù)操作。

MyBatis-Plus開發(fā)者寫了一個(gè)多數(shù)據(jù)源叫dynamic-datasource-spring-boot-starter ,非常簡單易用。

dynamic-datasource-spring-boot-starter文檔

官方文檔部分截圖:

第三方集成的,基本上是目前比較主流的(用的比較多)。

一、添加Maven依賴

<dependency>
  <groupId>com.baomidou</groupId>
  <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
  <version>2.5.4</version>
</dependency>

二、配置文件修改(application.yml)

spring:
 datasource:
  dynamic:
   primary: db1 #設(shè)置默認(rèn)的數(shù)據(jù)源,默認(rèn)值為master
   datasource:
    db1: #數(shù)據(jù)源db1
     driver-class-name: com.mysql.jdbc.Driver
     url: jdbc:mysql://127.0.0.1:3306/wordpress_master?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
     username: root
     password: 123456
    db2: #數(shù)據(jù)源db2
     driver-class-name: com.mysql.jdbc.Driver
     url: jdbc:mysql://127.0.0.1:3306/wordpress_slave?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
     username: root
     password: 123456
   type: com.alibaba.druid.pool.DruidDataSource
   druid:
    initial-size: 10
    max-active: 100
    min-idle: 10
    max-wait: 60000
    pool-prepared-statements: true
    max-pool-prepared-statement-per-connection-size: 20
    time-between-eviction-runs-millis: 60000
    min-evictable-idle-time-millis: 300000
    #Oracle需要打開注釋
    #validation-query: SELECT 1 FROM DUAL
    test-while-idle: true
    test-on-borrow: false
    test-on-return: false
    stat-view-servlet:
     enabled: true
     url-pattern: /druid/*
     #login-username: admin
     #login-password: admin
    filter:
     stat:
      log-slow-sql: true
      slow-sql-millis: 1000
      merge-sql: false
     wall:
      config:
       multi-statement-allow: true

三、完成成1、2步后,啟動(dòng)應(yīng)用

如果控制臺不報(bào)錯(cuò)且出現(xiàn)如下圖所示,就表示成功整合:

四、注意事項(xiàng)

啟動(dòng)主類需要排除Druid相關(guān)依賴,否則會出現(xiàn)如下錯(cuò)誤:

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

解決辦法,加上如下代碼即可:

@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)

到此這篇關(guān)于MyBatis-Plus實(shí)現(xiàn)多數(shù)據(jù)源的示例代碼的文章就介紹到這了,更多相關(guān)MyBatis-Plus 多數(shù)據(jù)源內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

绥江县| 清新县| 康定县| 汶上县| 棋牌| 望都县| 德兴市| 册亨县| 四平市| 赤水市| 萨嘎县| 浑源县| 黑水县| 个旧市| 德令哈市| 馆陶县| 栾城县| 徐闻县| 石渠县| 榆中县| 句容市| 连山| 东阿县| 比如县| 潼关县| 龙口市| 天镇县| 色达县| 定边县| 临沭县| 江津市| 长汀县| 西畴县| 扶绥县| 农安县| 乐安县| 上饶市| 堆龙德庆县| 霍州市| 桃园市| 花莲县|