av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Springboot mybatis plus druid多數(shù)據(jù)源解決方案 dynamic-datasource的使用詳解

瀏覽:36日期:2023-04-07 17:36:49

依賴(lài)

<dependency> <groupId>com.baomidou</groupId> <artifactId>dynamic-datasource-spring-boot-starter</artifactId> <version>2.5.0</version></dependency><dependency> <groupId>p6spy</groupId> <artifactId>p6spy</artifactId> <version>3.9.1</version></dependency><dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.21</version></dependency><dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.3.1.tmp</version></dependency>

p6spy配置文件spy.properties,有性能影響,生產(chǎn)環(huán)境建議關(guān)閉

#3.2.1以上使用modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory#3.2.1以下使用或者不配置#modulelist=com.p6spy.engine.logging.P6LogFactory,com.p6spy.engine.outage.P6OutageFactory# 自定義日志打印logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger#日志輸出到控制臺(tái)appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger# 使用日志系統(tǒng)記錄 sql#appender=com.p6spy.engine.spy.appender.Slf4JLogger# 設(shè)置 p6spy driver 代理deregisterdrivers=true# 取消JDBC URL前綴useprefix=true# 配置記錄 Log 例外,可去掉的結(jié)果集有error,info,batch,debug,statement,commit,rollback,result,resultset.excludecategories=info,debug,result,commit,resultset# 日期格式dateformat=yyyy-MM-dd HH:mm:ss# 實(shí)際驅(qū)動(dòng)可多個(gè)#driverlist=org.h2.Driver# 是否開(kāi)啟慢SQL記錄outagedetection=true# 慢SQL記錄標(biāo)準(zhǔn) 2 秒outagedetectioninterval=5

配置文件application.yml

server: port: 8080spring: datasource: dynamic: p6spy: true # 默認(rèn)false,建議線(xiàn)上關(guān)閉。 primary: master #設(shè)置默認(rèn)的數(shù)據(jù)源或者數(shù)據(jù)源組,默認(rèn)值即為master datasource: master: url: jdbc:mysql://localhost:3306/bdata?serverTimezone=GMT%2B8&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=true&allowMultiQueries=true username: root password: root driver-class-name: com.mysql.cj.jdbc.Driver slave: url: jdbc:mysql://localhost:3306/lmkstudy?serverTimezone=GMT%2B8&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=true&allowMultiQueries=true username: root password: root driver-class-name: com.mysql.cj.jdbc.Driver druid: password: root username: root # 初始化連接大小 initial-size: 5 #最大連接池?cái)?shù)量 max-active: 20 # 最小連接池?cái)?shù)量 min-idle: 3 # 配置獲取連接等待超時(shí)的時(shí)間 單位毫秒 max-wait: 60000 # 配置間隔多久才進(jìn)行一次檢測(cè),檢測(cè)需要關(guān)閉的空閑連接,單位是毫秒 time-between-eviction-runs-millis: 60000 # 配置一個(gè)連接在池中最小生存的時(shí)間,單位是毫秒 min-evictable-idle-time-millis: 300000 # 測(cè)試連接 validation-query: select # 申請(qǐng)連接的時(shí)候檢測(cè),建議配置為true,不影響性能,并且保證安全性 test-while-idle: true # 獲取連接時(shí)執(zhí)行檢測(cè),建議關(guān)閉,影響性能 test-on-borrow: false # 歸還連接時(shí)執(zhí)行檢測(cè),建議關(guān)閉,影響性能 test-on-return: false # 打開(kāi)PSCache,并且指定每個(gè)連接上PSCache的大小 pool-prepared-statements: true # 配置監(jiān)控統(tǒng)計(jì)攔截器 防火墻 日志配置 # stat監(jiān)控?cái)?shù)據(jù)庫(kù)性能 # wall 用于防火墻 # 日志 slf4j logback # log4j # log4j2 # 配置多個(gè)英文逗號(hào)分隔 filters: stat,wall,slf4j max-pool-prepared-statement-per-connection-size: 20 # 合并多個(gè)DruidDataSource的監(jiān)控?cái)?shù)據(jù) use-global-data-source-stat: true # 通過(guò)connectProperties屬性來(lái)打開(kāi)mergeSql功能;慢SQL記錄 SQL優(yōu)化 connect-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 # ===========監(jiān)控配置=========== # WebStatFilter配置,說(shuō)明請(qǐng)參考Druid Wiki,配置_配置WebStatFilter web-stat-filter: #是否啟用StatFilter默認(rèn)值false enabled: true # 攔截所有的 url-pattern: /* # 排除一些不必要的url,比如*:js,/jslib/*等等: exclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico, /druid/*' # 關(guān)閉和開(kāi)啟session 統(tǒng)計(jì)功能 默認(rèn)關(guān)閉 # session-stat-enable: true # sessionStatMaxCount是1000個(gè) # session-stat-max-count: 1000 # 配置principalSessionName,使得druid能夠知道當(dāng)前的session的用戶(hù)是誰(shuí) # principal-session-name: # StatViewServlet配置,說(shuō)明請(qǐng)參考Druid Wiki,配置_StatViewServlet配置 stat-view-servlet: # 是否啟用StatViewServlet默認(rèn)值true enabled: true url-pattern: /druid/* # 界面上有一個(gè)重置功能 執(zhí)行這個(gè)操作之后,會(huì)導(dǎo)致所有計(jì)數(shù)器清零,重新計(jì)數(shù) 建議false reset-enable: false # 登錄的后臺(tái)的用戶(hù)名,密碼 login-username: admin login-password: adminmybatis-plus: type-aliases-package: com.site.datasource.entity mapper-locations: classpath*:mapper/*.xml

service層添加注解@DS(“slave”),選定數(shù)據(jù)源

@DS('slave')@Service('userService')public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {}

啟動(dòng)類(lèi)上添加@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)

@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)public class ThreadApplication { public static void main(String[] args) { SpringApplication.run(ThreadApplication.class, args); }}

遇到的坑:記得要去掉DruidConfig這個(gè)文件,不然會(huì)報(bào)錯(cuò)

到此這篇關(guān)于Springboot mybatis plus druid多數(shù)據(jù)源解決方案 dynamic-datasource的使用的文章就介紹到這了,更多相關(guān)Springboot mybatis plus druid多數(shù)據(jù)源內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 在线视频99 | 欧美精品第一页 | 天堂资源 | 人人干人人玩 | 男女污污网站 | 日韩成人高清在线 | 日本一区视频在线观看 | 人人亚洲| 亚洲精品国产综合区久久久久久久 | 久久青视频 | 国产精品精品久久久 | 玖玖操 | 在线视频一区二区三区 | 性做久久久久久免费观看欧美 | 久草网站 | 精品国产黄色片 | 精品一区二区三区在线观看国产 | 精精国产xxxx视频在线播放 | 亚洲一区在线日韩在线深爱 | 成人在线免费观看 | 国产一二三区精品视频 | 四虎最新地址 | 一区二区三区国产好的精 | 国产传媒毛片精品视频第一次 | 欧美日韩综合一区 | 色性av| 夜夜草av| 中国av在线免费观看 | 麻豆changesxxx国产 | 亚洲一区二区三区免费 | 久久久久国产一区二区三区四区 | 成人福利网站 | 亚洲成人免费在线观看 | 国产91精品在线 | 午夜在线精品偷拍 | 国产激情一区二区三区 | 99久久久无码国产精品 | 大陆一级毛片免费视频观看 | 久久成人人人人精品欧 | aacc678成免费人电影网站 | 国产精品1区2区 |