第一步
引入依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>3.5.0</version>
</dependency>
第二步
配置文件
datasource:
dynamic:
primary: mysqlData
datasource:
mysqlData:
username: xxx
password: xxx
driver-class-name: com.mysql.cj.jdbc.Driver
url: xxx
# type: com.zaxxer.hikari.HikariDataSource
sqlServerData:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jxxxxx
username: xxxx
password: xxxx
主数据源是 mysqldata 默认的数据源头
需要切换其他数据源
@Service
@DS("sqlServerData")
@Slf4j
@RequiredArgsConstructor
public class xxximpl implements xxxservice{
@DS可以使用在service 或者mapper文件上面 简单高效,之前老项目多数据源使用的原生jdbc 本次进行优化记录
1890

被折叠的 条评论
为什么被折叠?



