How to switch multiple data sources with SpringBoot + DynamicDataSource
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!