Spring Boot整合MyBatis多数据源

Spring Boot整合MyBatis多数据源

  对于Spring Boot 整合JdbcTemplate多数据源,此方式相对比较复杂一些,没有整合JdbcTemplate多数据源相对简单一些,但此方式也是一种技术,我们也是要掌握的。

创建工程

首先我们需要创建一个Spring Boot 项目工程,并且添加Mybatis、Mysql以及web的相关依赖:
在这里插入图片描述
创建好项目后,由于我们每个人的数据库版本不一样,我们要自己指定版本号,这里,我的数据库版本使用的依赖时5.1.47版本的,并且添加数据库连接池Druid依赖,我们整合JdbcTemplate时也是要添加Druid依赖,但是我们要添加Spring Boot打造的Druid,不能使用传统的Druid。依赖如下:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.0.1</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
            <version>5.1.47</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.16</version>
        </dependency
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值