SpringBoot中starter场景启动器

1.starter的作用

starter一句话来描述就是开发中我们引入了相关场景的starter,这个场景中所有的相关依赖都引入进来了,比如我们做web开发引入了:

		<!--web插件-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

该starter将导入与web开发相关的所有包,如下:
在这里插入图片描述
分析依赖树如下:
在这里插入图片描述
可以看到我们就引入了一个spring-boot-starter-web,他帮我们引入了spring-webmvc,spring-web开发模块,还引入了spring-boot-starter-tomcat场景,spring-boot-starter-json场景,这些场景下面又引入了一大堆相关的包。

总结:
starter包含许多依赖项,这些依赖项可以快速启动和运行一个项目,导入starter获得所需的所有Spring和相关技术的一站式服务,而不必搜索示例代码和复制粘贴大量依赖描述符。

2.官方提供的starter

在开发中我们经常会用到spring-boot-starter-xxx ,这xxx可以是web,也就是上述中的spring-boot-starter-web,该场景是用作web开发。
也就是说xxx是某种开发场景。
我们只要引入starter,这个场景的所有常规需要的依赖我们都自动引入。
SpringBoot支持的所有场景如下:
https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-starter

3.第三方starter

第三方启动程序不应该从spring-boot开始,因为它是为官方spring-boot工件保留的。相反,第三方启动程序通常以项目名称开头。例如,名为thirdpartyproject的第三方启动程序项目通常被命名为thirdpartyproject-spring-boot-starter。
也就是说:xxx-spring-boot-starter是第三方为我们提供的简化开发的场景启动器。

4.所有场景启动器最基本的依赖

所有场景启动器最基本的依赖就是spring-boot-starter:

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
      <version>2.4.1</version>
      <scope>compile</scope>
    </dependency>

这个依赖也就是SpringBoot自动配置的核心依赖。

猜你喜欢

转载自blog.csdn.net/MrYushiwen/article/details/111869133