当前位置:网站首页>Multiple data source configuration
Multiple data source configuration
2022-08-07 13:33:00 【inexaustible】
1. SpringBoot uses MyBatisPlus configuration
1. baomidou dynamic data source (@DS)
Thinking:
1. Introducing dependencies
2. Modify Application.yml to configure multiple data source information
3. Use @DS to switch data sources
1.1, import dependencies
com.baomidou dynamic-datasource-spring-boot-starter 3.2.1 1.2, configuration file
spring:# Data source configuration itemsautoconfigure:exclude:- com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # Exclude Druid's automatic configuration, use dynamic-datasource-spring-boot-starter to configure multiple data sourcesdatasource:druid: # Druid [monitoring] related global configurationweb-stat-filter:enabled: truestat-view-servlet:enabled: trueallow: # Set a whitelist, if not filled, all access is allowedurl-pattern: /druid/*login-username: # Console management username and passwordlogin-password:filter:stat:enabled: truelog-slow-sql: true # slow SQL loggingslow-sql-millis: 100merge-sql: truewall:config:multi-statement-allow: truedynamic: # Multiple data source configurationdruid: # Druid [connection pool] related global configurationinitial-size: 5 # initial number of connectionsmin-idle: 10 # Minimum number of connection poolsmax-active: 20 # maximum number of connection poolsmax-wait: 600000 # Configure the timeout time for obtaining a connection, in millisecondstime-between-eviction-runs-millis: 60000 # Configure how long the interval is to be checked to detect idle connections that need to be closed, unit: millisecondsmin-evictable-idle-time-millis: 300000 # Configure the minimum lifetime of a connection in the pool, in millisecondsmax-evictable-idle-time-millis: 900000 # Configure the maximum lifetime of a connection in the pool, in milliseconds# validation-query: SELECT 1 FROM DUAL # Configure to check whether the connection is validtest-while-idle: truetest-on-borrow: falsetest-on-return: false# Set the default data source or data source group, the default value is masterprimary: masterdatasource:# main data sourcemaster:name: lc_mono_camasurl: jdbc:mysql://10.1.102.24:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTTdriver-class-name: com.mysql.jdbc.Driverusername: lc_mono_camaspassword: [email protected]_1706cmds_finger:name: cmds_finger# url: jdbc:sqlite:lib/tidefinger/cms_finger.db?date_string_format=yyyy-MM-dd HH:mm:ssurl: jdbc:sqlite:D:/lcProject/lc-mono-camas-java/lc-camas/lib/cms_finger.db?date_string_format=yyyy-MM-dd HH:mm:ssdriver-class-name: org.sqlite.JDBCusername:password:1.3. Use @DS to switch data sources
@DS("cmds_finger")public List selectAll(JSONObject reqJson) {return tideTideMapper.selectAll(reqJson);} 2, @DS annotation description
Usage of @DS
@DS can annotate on methods, classes, interfaces, and enumerations.
FAQ:When it comes to switching data sources,
1. Transactions cannot be used, otherwise the data source will not be switched, and the data source loaded for the first time is still used.
Delete the @Transactional() annotation on the method or class or interface that operates multiple data sources.
2. After the data source loaded for the first time, operate other data sources for the second time (third time...), if the data source does not exist, use the data source loaded for the first time
3. The data source name should not contain a glide line, and the data source of the glide line cannot be switched
Second, bean configuration
边栏推荐
- Rust is one of the common problems: Blocking waiting for file lock on package cache
- 金九银十面试季在即,Android程序猿如何斩获offer?
- mysql 主从复制部署
- The Golden Nine Silver Ten interview season is coming, how does the Android programmer get the offer?
- 2022年广东省安全员A证第三批(主要负责人)考试模拟100题及在线模拟考试
- tensorRT(一)| tensorRT如何进行推理加速?
- Yangzhou University responded that "Dr. Tsinghua has been employed for 5 years, and the monthly salary is only 372 yuan"
- Reason for MySQL error: ERROR 1241 (21000): Operand should contain 1 column(s)
- 数据治理(二):数据治理功能方面
- 机器学习实战(1)——概览
猜你喜欢

SkyWalking+.NET5初体验

DiskGenius Installation Tutorial

2022/8/5 Topological sort+dp

校园篮球网页作业成品 运动系列NBA篮球主题 学校篮球网页制作模板 学生简单体育运动网站设计成品

Yangzhou University responded that "Dr. Tsinghua has been employed for 5 years, and the monthly salary is only 372 yuan"

2022年流动式起重机司机试题模拟考试平台操作

USB Module Analysis (4) - Device List & Permission Application

VMware's record of virtual machine expansion

蓝图传值给Niagara

Weekend resumption, masters do not sell products but tell stories!
随机推荐
8.cuBLAS开发指南中文版--cuBLAS中的cublasGetMatrix()和cublasSetMatrix()
Developer Growth Incentive Program - Development Notes: The Simplest Steps to Transplant LVGL
ENScanGo主域名批量提取脚本
LeetCode高频题:最长公共子序列,玩游戏A和游戏B,两兄弟加起来最多可以获得多少奖品
MySQL报错原因:ERROR 1292 (22007): Incorrect date value: ‘1988‘ for column ‘birthday‘ at row 1
CSO face to face | Dialogue with mini world, talk about the safety construction of the game industry
Configure code snippets in Visual Studio Code to easily generate code templates with shortcut keys
机器学习实战(1)——概览
Yolo v5 masks monitoring
【MySql进阶】索引详解(二):Mysql InnoDB索引原理、B+树、聚簇索引、二级索引、联合索引
ReentrantReadWriteLock Read-write lock
helm installation error Request entity too large: limit is 3145728
我用开天平台做了一个“网络图片文字识别”小工具【开天aPaaS大作战】
Red team web management information collection
Machine Learning in Practice (1) - Overview
【ASM】字节码操作 MethodVisitor 案例实战 cinit 方法生成
rpc.rquotad: unable to register (RQUOTAPROG, RQUOTAVERS, udp)
方正中期期货是正规期货公司吗?开户安全吗?
ZCMU--2126: 分分钟的碎碎念
PDF转换工具安装教程