In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you SpringBoot + DynamicDataSource how to switch multiple data sources, I believe that most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Just started using a data source, but it is required to do multiple data source switching. Look, the framework has its own data source that can be cut, but the data source is fixed in the YML file.
Fixed multiple data sources switch 1. Since I have my own DynamicDataSource package in this version
I won't introduce it.
If you look at the lack of bags, go to maven and check Dynamic-DataSource first.
two。 Configure two data sources in yml
3. Get the method of starting connection pool at startup
Configure in the APPLICATION startup class
4. Load each connection pool
Load each connection pool into the dynamicDataSource class, where the an in the dynamicDataSource method represents the default connection pool b is a map in which the connection pools are stored, in which the key value can be defined by itself. Here the key value is directly first,second.
In the 5.dynamicDataSource class
6. Perform a switch operation in a section
As for how to add noodles to Baidu on its own. The parameter passed in from the section and then call the setDataSource method just mentioned to pass the string in.
Then the fixed switching is almost complete. Just add @ DataSource in front of the called service to enter the section to switch.
The above is all the content of the article "SpringBoot + DynamicDataSource how to switch multiple data sources". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.