Explain in detail how spring boot integrates mybatis to realize Druid multi data source configuration
1、 Application scenario of multiple data sources
At present, the popular data operation framework in the industry is mybatis. What is Druid?
Druid is a database connection pool component of Java. Druid can provide powerful monitoring and extension functions. For example, SQL can be monitored, and slow query SQL list can be queried in the monitoring business. Druid core mainly includes three parts:
1. Druiddriver agent can provide a plug-in system based on filter chain mode.
2. Druiddatasource efficient and manageable database connection pool
3. sqlParser
When the volume of business data reaches a certain level, DBA needs to reasonably configure database resources. That is, configure the machine high configuration of the main library, and put the core high-frequency data on the main library; Put the secondary data in the slave library, low configuration. Increase revenue and reduce expenditure, that's what I mean. Putting data in different databases requires data manipulation through different data sources. Here we take the springboot mybatis mutil datasource project as an example:
The user table is on the master database, and the address table city is on the cluster database. The following implementation obtains the user information according to the user name, including the address information of the slave library. The rest API needs to obtain data from the master library and the slave library respectively, and assemble and return it at the business logic layer. The logic diagram is as follows:
Let's run this case.
2、 Run the springboot mybatis mutil datasource project case
Project address: springboot learning_ jb51. rar。 Start running the project steps below:
Project address: springboot learning_ jb51. rar