Springboot+MyBatis-Plus+druid多数据源配置实现
一.背景
业务上需求或者业务的扩展需要分库,多数据源的配置使用在业务开发中常常会用到。MyBatis-plus官网(https://mp.baomidou.com/guide/dynamic-datasource.html)对如何配置多数据源给出了范例,但对于整合druid数据库连接池却没有具体的实施范例。
线上关于整合这几个框架的博文处于互抄的状态,笔者亲自验证都没能实现,且实现复杂。本篇宗旨快速集成三大框架,少走弯路。
二.依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.5.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<!--测试类-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--Web启动类,可以进行restful风格接口注解-->
<dependency