springboot xxx-starter-xxx是什么(启动器)

介绍

在做springboot开发时,需要添加很多xxx-starter-xxx依赖,xxx-starter-xxx称之为启动器

主要功能:

  1. 用来简化maven依赖配置。已经添加了某功能相关的 依赖 和 版本号
  2. 有时做一些初始化的配置

需要某个功能时,就添加该功能的xxx-starter-xxx依赖,相关的jar包就会自动导入进来

注意: 有些xxx-starter-xxx一旦添加后,就需要 添加 配置文件 和 代码,否则会报错。因为启动工程时,会初始化该功能,但没有相应代码,就会报错

例子

查看工程依赖,如下图:

spring-boot-starter-web 主要依赖如下:

  • spring-boot-starter:springboot启动器
  • org.apache.tomcat.embed:嵌入式tomcat
  • spring-web:spring
  • spring-webmvc:spring-mvc

依赖截取如下:

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.2.2.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
<version>2.2.2.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.2.2.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>2.2.2.RELEASE</version>
<scope>compile</scope>
<exclusions>
    <exclusion>
    <artifactId>tomcat-embed-el</artifactId>
    <groupId>org.apache.tomcat.embed</groupId>
    </exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.2.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.2.RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>

常见starter

https://docs.spring.io/spring-boot/docs/2.2.8.RELEASE/reference/html/using-spring-boot.html#using-boot-starter


原文出处:/show_1EF5qjfuNMJj.html