Spring Boot 整合 Mybatis 实现 Druid 多数据源配置

This commit is contained in:
JeffLi1993
2017-03-23 17:43:30 +08:00
committed by liqiangqiang
parent 8157c99170
commit 60e91f7ee0
3 changed files with 9 additions and 7 deletions

View File

@@ -43,13 +43,6 @@
<version>${mybatis-spring-boot}</version> <version>${mybatis-spring-boot}</version>
</dependency> </dependency>
<!-- Druid 数据连接池依赖 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid}</version>
</dependency>
<!-- MySQL 连接驱动依赖 --> <!-- MySQL 连接驱动依赖 -->
<dependency> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
@@ -57,6 +50,13 @@
<version>${mysql-connector}</version> <version>${mysql-connector}</version>
</dependency> </dependency>
<!-- Druid 数据连接池依赖 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid}</version>
</dependency>
<!-- Junit --> <!-- Junit -->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>

View File

@@ -18,6 +18,7 @@ import javax.sql.DataSource;
// 扫描 Mapper 接口并容器管理 // 扫描 Mapper 接口并容器管理
@MapperScan(basePackages = ClusterDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "clusterSqlSessionFactory") @MapperScan(basePackages = ClusterDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "clusterSqlSessionFactory")
public class ClusterDataSourceConfig { public class ClusterDataSourceConfig {
// 精确到 cluster 目录,以便跟其他数据源隔离 // 精确到 cluster 目录,以便跟其他数据源隔离
static final String PACKAGE = "org.spring.springboot.dao.cluster"; static final String PACKAGE = "org.spring.springboot.dao.cluster";
static final String MAPPER_LOCATION = "classpath:mapper/cluster/*.xml"; static final String MAPPER_LOCATION = "classpath:mapper/cluster/*.xml";

View File

@@ -19,6 +19,7 @@ import javax.sql.DataSource;
// 扫描 Mapper 接口并容器管理 // 扫描 Mapper 接口并容器管理
@MapperScan(basePackages = MasterDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "masterSqlSessionFactory") @MapperScan(basePackages = MasterDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "masterSqlSessionFactory")
public class MasterDataSourceConfig { public class MasterDataSourceConfig {
// 精确到 master 目录,以便跟其他数据源隔离 // 精确到 master 目录,以便跟其他数据源隔离
static final String PACKAGE = "org.spring.springboot.dao.master"; static final String PACKAGE = "org.spring.springboot.dao.master";
static final String MAPPER_LOCATION = "classpath:mapper/master/*.xml"; static final String MAPPER_LOCATION = "classpath:mapper/master/*.xml";