多数据源处理-苞米豆-dynamic
生活随笔
收集整理的這篇文章主要介紹了
多数据源处理-苞米豆-dynamic
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
微服務(wù)項(xiàng)目雖然每個(gè)服務(wù)可以單獨(dú)使用一個(gè)庫,但是某些特定服務(wù),如調(diào)度中心服務(wù),定時(shí)任務(wù)等,如果還是使用rpc或者fegin頻繁進(jìn)行遠(yuǎn)程調(diào)用,總感覺不是很合適
所以對單服務(wù)進(jìn)行了多數(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>整體架構(gòu)是 mybatisplus+druid+dynamic+xxl-job
其實(shí)集成比較簡單,不需要關(guān)系entity對應(yīng)哪個(gè)庫,自動(dòng)識(shí)別的
配置文件如下
server:port: 18871spring:application:name: cloud-scheduledatasource:druid:stat-view-servlet:enabled: truedynamic:primary: dmsPro #設(shè)置默認(rèn)的數(shù)據(jù)源或者數(shù)據(jù)源組,默認(rèn)值即為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個(gè)庫 dmsPro? dmsDev? ekp2Dev?
主庫為dmsPro
?
多數(shù)據(jù)源處理代碼:
1.druid去除默認(rèn)配置
2.@DS注解使用
@DS注解標(biāo)識(shí)會(huì)默認(rèn)走標(biāo)識(shí)的從庫
未配置會(huì)走默認(rèn)dmsPro主庫
@DS可以標(biāo)識(shí)在類和方法上,方法優(yōu)先于類
總結(jié)
以上是生活随笔為你收集整理的多数据源处理-苞米豆-dynamic的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux7使用光盘作为本地repo源
- 下一篇: 台达伺服电机选型手册_机械加工工艺师手册