springboot 配置多数据源查询

本文介绍了如何在SpringBoot 2.2.12.RELEASE环境中,结合mysql8.0.2和postgres13.2数据库进行多数据源配置。通过引入mybatis和dynamic-datasource-spring-boot-starter依赖,实现数据源切换。查询mysql数据库时,只需在mapper添加@DS("master")注解。
摘要由CSDN通过智能技术生成

一.开发环境:

springboot 2.2.12.RELEASE
mysql 8.0.2
postgres 13.2

二.安装maven依赖

  1. mysql 依赖
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<scope>runtime</scope>
		</dependency>
  1. pg依赖
	<dependency>
			<groupId>org.postgresql</groupId>
			<artifactId>postgresql</artifactId>
			<scope>runtime</scope>
	</dependency>

3.多数据源配置依赖

		<dependency>
			<groupId>com.baomidou</groupId>
			<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
			<version>3.4.0</version>
		</dependency>

三.添加配置信息

在这里插入图片描述

四.调用方式

mysql数据库的查询只需在 mapper添加注释@DS("master")
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值