场景:

随着业务发展,系统连接多数据库成为常态,继前面AOP的实现方式之后,这里记录一下分包实现的方式。

实现:

 1.pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mumu</groupId>
<artifactId>springboot-mumu</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>mumu-web</artifactId> <dependencies>
<!-- web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- aop -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- sqlserver -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>runtime</scope>
</dependency>
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.5</version>
</dependency> </dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>

2.配置文件

server:
port: 9587
spring:
datasource:
hikari:
master:
driverClassName: com.mysql.cj.jdbc.Driver
jdbcUrl: jdbc:mysql://127.0.0.1:3306/boltloan?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8
username: root
password: 123456
slave:
driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbcUrl: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=TestDB
username: SA
password: <1234567890@Passw0rd>
#mybatis-plus
mybatis-plus:
type-aliases-package: com.mumu.model
mapper-locations: classpath:/mapper/**/*.xml
configuration:
jdbc-type-for-null: null
map-underscore-to-camel-case: true
cache-enabled: false
global-config:
db-config:
id-type: auto
field-strategy: not_empty

3.数据源配置类

采用注解的方式:每种数据源,使用一个对应 注解!

敬请期待...

最新文章

  1. Yii2的深入学习--行为Behavior
  2. kvm/qemu/libvirt学习笔记 (1) qemu/kvm/libvirt介绍及虚拟化环境的安装
  3. Hive几种数据导出方式
  4. iOS界面开发
  5. golang 文件读取
  6. OpenGL开发环境配置-Windows/MinGW/Clion/CMake
  7. [Angularjs]asp.net mvc+angularjs+web api单页应用
  8. #region 自适应屏幕分辨率
  9. 转-Fragment+ViewPager组件(高仿微信界面)
  10. UIFontFamily
  11. glassfish 一个bug重现
  12. OpenGL ES 2.0 符点精度
  13. VxWorks6.6 pcPentium BSP 使用说明(二):创建启动盘
  14. [译]漫画SELinux概念
  15. TXDragon的大火题合集
  16. MySQL语句高效写法整理
  17. Matplotlib中柱状图bar使用
  18. Prior Posterior和Likelihood的理解与几种表达方式
  19. 推导式_字典_enumerate
  20. TStringList的用法

热门文章

  1. 【基础】Hint控制语句执行
  2. thinkphp sql解析缓存
  3. php的字符串{}选定与{变量}
  4. DELPHI 让子窗体显示在任务栏上
  5. hive的复合数据类型
  6. NOIp2018集训test-10-6/test-10-7 (联考五day1/day2)
  7. 20140422 ALT+F8 四个强制类型转换
  8. 16-Ubuntu-文件和目录命令-切换目录-cd
  9. libevent的使用 32位 64位
  10. Ajax.BeginForm 在 Chrome下的问题