日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

多数据源处理-苞米豆-dynamic

發(fā)布時間:2025/3/15 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 多数据源处理-苞米豆-dynamic 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

微服務項目雖然每個服務可以單獨使用一個庫,但是某些特定服務,如調(diào)度中心服務,定時任務等,如果還是使用rpc或者fegin頻繁進行遠程調(diào)用,總感覺不是很合適

所以對單服務進行了多數(shù)據(jù)源處理

使用的是苞米豆的 dynamic-datasource-spring-boot-starter

<!-- dynamic 多數(shù)據(jù)源--><dependency><groupId>com.baomidou</groupId><artifactId>dynamic-datasource-spring-boot-starter</artifactId><version>3.0.0</version></dependency>

整體架構是 mybatisplus+druid+dynamic+xxl-job

其實集成比較簡單,不需要關系entity對應哪個庫,自動識別的

配置文件如下

server:port: 18871spring:application:name: cloud-scheduledatasource:druid:stat-view-servlet:enabled: truedynamic:primary: dmsPro #設置默認的數(shù)據(jù)源或者數(shù)據(jù)源組,默認值即為master# 配置全局druid參數(shù),請按需配置druid:initial-size: 10max-active: 100min-idle: 5max-wait: 6000validation-query: 'select 1'pool-prepared-statements: truemax-pool-prepared-statement-per-connection-size: 100#dynamic開始多數(shù)據(jù)源配置datasource:dmsPro:username: xxxpassword: xxxurl: xxxdriver-class-name: xxxdmsDev:username: xxxpassword: xxxurl: xxxdriver-class-name: xxxekp2Dev:username: xxxpassword: xxxurl: xxxdriver-class-name: xxx management:endpoints:web:exposure:include: '*'xxl:job:admin:addresses: http://xxx/xxl-job-adminaccessToken:executor:appname: xxl-job-executor-Sap2Biaddress:ip:port: -1logpath: /data/applogs/xxl-job/jobhandlerlogretentiondays: 30#mybatis-plus mybatis-plus:configuration:cache-enabled: falsemap-underscore-to-camel-case: trueglobal-config:id-type: 0field-strategy: 0db-column-underline: truerefresh-mapper: truetypeAliasesPackage: com.xx.xx.executor.core.bean.entitymapper-locations: classpath:com/xx/xx/*/mapper/*.xmllogging:level:com.baomidou: debug

如配置文件,目前有3個庫 dmsPro? dmsDev? ekp2Dev?

主庫為dmsPro

?

多數(shù)據(jù)源處理代碼:

1.druid去除默認配置

2.@DS注解使用

@DS注解標識會默認走標識的從庫

未配置會走默認dmsPro主庫

@DS可以標識在類和方法上,方法優(yōu)先于類

總結

以上是生活随笔為你收集整理的多数据源处理-苞米豆-dynamic的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。