Spring boot integrates mybatis to realize master-slave (multi data source) separation scheme example

This article will introduce the use of spring boot to integrate mybatis and realize the separation of master and slave libraries (also applicable to multiple data sources). Continue the previous spring boot integration of mybatis. The project will also integrate the paging plug-in PageHelper, general mapper and Druid.

Create a new Maven project, and the final project structure is as follows:

Inject multiple data sources into sqlsessionfactory

POM adds the following dependencies:

It should be noted here that the project is implemented by extending the org. Org. Of mybatis spring boot starter mybatis. spring. boot. autoconfigure. Mybatisautoconfiguration to implement multi data source injection. In mybatis spring boot starter: 1.2 0, this class cancels the default constructor, so this project still uses 1.1 Version 0. We need to pay attention to whether the extension will be reopened in subsequent versions.

The reason why I still use the old scheme is that I personally think open expansion is reasonable and believe it will return in future versions.

If you need other solutions, please refer to the portal

This article uses code

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>