当前位置:网站首页>Guns framework multi data source configuration without modifying the configuration file
Guns framework multi data source configuration without modifying the configuration file
2022-06-12 05:58:00 【The stars can count people】
Project requirements , Configure multiple data sources , I also found a lot on the Internet , But there are many configuration items , and Guns It comes with multiple data source facets AOP, Didn't use it . I interrupted and looked at the configuration , Found a solution :
- stay database_info Insert information about the new data source into the table

- Annotate the methods that need to switch data sources @DataSource(name = “dataSourceBiz”)
@Override
@DataSource(name = "dataSourceBiz")
public List<SysAlarm> getAll() {
System.out.println(DataSourceContextHolder.getDataSourceType());
return this.baseMapper.selectList(null);
}
name The value of is written in the database db_name field value
- result
Query results of the master data source :
Query results of the second data source :
The output is DataSourceContextHolder.getDataSourceType(), That's the data source
Guns The framework has written the switching of multiple data sources , So we don't have to write our own configuration , The configuration of the framework itself is as follows :
1. DataSourceConfig class

The project will start with DataSourceConfig Class , Configure the master data source , Namely application-local.yml or dev.yml Database configured in ,prefix The mapping is yml Inside spring.datasource
then , Create a master database instance 
After a series of database operations , Will enter the following :
The corresponding is MultiSourceExAop class
2. SqlSessionFactoryConfig class
Then go into this class , Create the primary database sqlsessionfactory
Initialize the master data source container and other data sources sqlsessionfactory Containers 
Within this method initBaseSqlSessionFactory Method will call all data sources in the database , except yml Master data source configured in , Other data is initialized in this method
3. DataSourceContext class
The initialization container related methods called in the multi data source switching template just mentioned are in this class 
4. MultiSourceExAop class
Switch the aspect of the data source , Scanning to @DataSource Triggered on annotation 
边栏推荐
- Multiple ways 99.9% to solve the problem of garbled code after copying text from PDF
- Towards End-to-End Lane Detection: an Instance SegmentationApproach
- [speech] how to customize ring back tone according to different countries
- Market trend report, technical innovation and market forecast of Chinese stump crusher
- [untitled]
- Golang idea configures the agent to improve the speed of packages downloaded by go get
- [long time series prediction] the [4] autocorrelation mechanism of aotoformer code explanation
- Rtmp/rtsp/hls public network real available test address
- China's elastic belt market trend report, technical dynamic innovation and market forecast
- Leetcode 第 80 场双周赛题解
猜你喜欢

Go interface oriented programming practice

Data integration framework seatunnel learning notes

What is the lszrz protocol used at ordinary times? Talk about xmodem/ymodem/zmodem

User login (medium)

CCF noi2022 quota allocation scheme

IO stream introduction

Leetcode-1043. Separate arrays for maximum sum

Es6-es11 learning

EBook list page

Quickly master makefile file writing
随机推荐
Available RTMP and RTSP test addresses of the public network (updated in March, 2021)
Multiple ways 99.9% to solve the problem of garbled code after copying text from PDF
SIM卡信号的驱动电流是多少mA,是否是可调节的?
RTMP streaming +rtmp playback low delay solution in unity environment
Types, functions and applications of intelligent sensors
Go interface implementation principle [advanced level]
[gpio] how to modify / display GPIO status through ADB shell
[Yu Yue education] basic reference materials of accounting of Nanjing Normal University
What is the difference between ArrayList and LinkedList?
Rtmp/rtsp/hls public network real available test address
Unity vscode cannot jump to definition
Halcon 3D 1 Reading 3D data
Leetcode buckle -10 Regular expression matching analysis [recursion and dynamic programming]
Memory model, reference and function supplement of program
数据库实验二:数据更新
A preliminary understanding of function
Divide a folder image into training set and test set
TCP and UDP introduction
IDEA常用配置
Halcon uses points to fit a plane