文章目录
概要
为了实现基于Spring Boot和MyBatis同时连接MySQL和PostgreSQL,
并根据不同的接口查询不同的数据源
我们可以配置两个数据源和两个SqlSessionFactory。下面是一个基本的实现示例:
1、添加依赖
提示:在pom.xml中添加必要的依赖:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>