Spring Boot 2.0 Multiple Data Source Programming

Before Spring Boot 1.5.x, there were already many tutorials and examples for multi-data source programming, such as Hengyu Junior's blog and Programmer DD's blog . I learned it from the tutorials of the two masters.

However, after upgrading to Spring Boot 2.0, some configurations and usages have changed. If you are not careful, you will encounter the error "jdbcUrl is required with driverClassName.", you can check the detailed error information here .

After a lot of hard work and searching for information, I finally found a solution, and I share it here to save latecomers from looking for information.

The first method:
use spring.datasource.jdbc-url in the configuration file instead of the usual spring.datasource.url. Enter image description
Here, I also ask the big guys to help explain the difference between spring.datasource.jdbc-url and spring.datasource.url.

The second method:
use the DataSourceProperties method in the data source configuration.
Enter image description

Finally, my WeChat account is chinesedragon, and the QR code is at the end. Friends are welcome to learn together.

GITEE source code https://gitee.com/shupengluo/SpringBoot2.0-MultiDataSource
GITHUB source code https://github.com/luoshupeng/SpringBoot2.0-MultiDataSource

Reference https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/htmlsingle/#howto-two-datasources

Enter image description

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324464821&siteId=291194637