springboot-配置多数据源之番外篇(分包实现)
2024-10-07 21:57:21
场景:
随着业务发展,系统连接多数据库成为常态,继前面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.数据源配置类
采用注解的方式:每种数据源,使用一个对应 注解!
敬请期待...
最新文章
- Yii2的深入学习--行为Behavior
- kvm/qemu/libvirt学习笔记 (1) qemu/kvm/libvirt介绍及虚拟化环境的安装
- Hive几种数据导出方式
- iOS界面开发
- golang 文件读取
- OpenGL开发环境配置-Windows/MinGW/Clion/CMake
- [Angularjs]asp.net mvc+angularjs+web api单页应用
- #region 自适应屏幕分辨率
- 转-Fragment+ViewPager组件(高仿微信界面)
- UIFontFamily
- glassfish 一个bug重现
- OpenGL ES 2.0 符点精度
- VxWorks6.6 pcPentium BSP 使用说明(二):创建启动盘
- [译]漫画SELinux概念
- TXDragon的大火题合集
- MySQL语句高效写法整理
- Matplotlib中柱状图bar使用
- Prior Posterior和Likelihood的理解与几种表达方式
- 推导式_字典_enumerate
- TStringList的用法