编写SpringBoot的自定义starter包

starter项目

先来看一下Starter的官方解释: 

Spring Boot Starter 是一种方便的依赖管理方式,它封装了特定功能或技术栈的所有必要依赖项和配置,使得开发者可以快速地将这些功能集成到Spring Boot项目中。Spring Boot官方提供了一系列的Starters,涵盖了从Web开发到安全、数据访问等多个方面

其实Starter是一种SDK思想,基于SDK高度抽象快速构建功能块或技术块是当下企业技术部门实现技术资产快速开发的利器,基于Spring的starter自然就是最高效的方法。

starter项目结构分析

我们先来看一下mybatis-spring-boot-starter的项目结构

抛开mybatis的jdbc等逐步演化的核心功能依赖,只专注我们想要参观的starter部分可以看到,mybatis-spring-boot-starter被引入后是以两个jar的形式存在,即

  • mybatis-spring-boot-autoconfigure
  • mybatis-spring-boot-starter 

其中,mybatis-spring-boot-starter 项目中并无代码,仅仅一个pom文件指明依赖

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot</artifactId>
    <version>2.1.4</version>
  </parent>
  <artifactId>mybatis-spring-boot-starter</artifactId>
  <name>mybatis-spring-boot-starter</name>
  <properties>
    <module.name>org.mybatis.spring.boot.starter</module.name>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <!--mybatis-starter的代码项目-->
    <dependency>
      <groupId>org.mybatis.spring.boot</groupId>
      <artifactId>mybatis-spring-boot-autoconfigure</artifactId>
    </dependency>

    <!-- 支撑mybatis-starter的其他依赖-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
    </dependency>
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
    </dependency>
  </dependencies>
</project>

也就是说, mybatis-starter与SpringBoot对接的主要逻辑集中在mybatis-spring-boot-autoconfigure 中,mybatis-spring-boot-starter  仅仅是个壳子,它统一管理mybati

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

糖拌西红柿多放醋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值