idea springboot 配置MySQL SQL server双数据库

该博客详细介绍了如何在IDEA中配置SpringBoot应用以连接MySQL和SQL Server两个不同的数据库。通过配置application.properties文件,分别设置主数据库(master)和辅助数据库(other)的数据源,接着展示具体的数据库配置细节。在启动类添加注解后,接口实现类可以调用这两个数据库。博主分享了个人测试及修改的经验,并提供了包结构的总览。
摘要由CSDN通过智能技术生成

首先导入相关的Jar包(其他最基本的就省略不写了)

		<dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
		<dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>6.2.2.jre8</version>
        </dependency>

然后配置 application.properties

在properties里面配置两个数据源 一个master 一个other并把相应的数据添加上

#注意classpath对应的位置 否则加载不到
mybatis.mapper-locations=classpath*:/*mapper/*.xml
spring.datasource.master.jdbc-url=jdbc:mysql://localhost:33051/plmss?useUnicode=true&characterEncoding=utf-8
spring.datasource.master.username=root
spring.datasource.master.password=root
spring.datasource.master.driver-class-name=com.mysql.jdbc.Driver

spring.datasource.other.jdbc-url=jdbc:sqlserver://localhost:1433;DatabaseName=user
spring.datasource.other.username=user
spring.datasource.other.password=user
spring.datasource.other.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver

主数据库配置:

新建一个datasource 里面专门放置 如图下

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值