本文主要介绍:
1. Spring Boot 是如何进行Jar的版本管理(spring-boot-starter-parent);
2. Spring Boot如何通过引入 Starter 引入所有功能相关的依赖(POM的依赖传递);
1. Spring Boot 是如何进行Jar的版本管理
所有Spring Boot项目,在创建时都必须依赖父项目.并定义父级依赖版本信息,如下为2.2.9.RELEASE(可修改)
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.9.RELEASE</version> <relativePath/> </parent>
在spring-boot-starter-parent中:
- properties中定义了java版本信息,编译源文件编码格式,编译后文件格式,Maven打包编译版本信息等
- resources中定义了资源新信息,针对application.yml/properties支持不同环境配置application*.yml/properties;
- pluginManagerment定义了插件及版本信息
************************************************************************
parent中定义了父依赖为spring-boot-dependencies
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${revision}</version>
<relativePath>../../spring-boot-dependencies</relativePath>
</parent>
在spring-boot-dependencies中:
properties中定义了jar的版本信息;
dependencyManagement中依赖的jar及properties中定义的版本信息
因此:spring-boot-starter-parent通过继承了spring-boot-denpendences,而spring-boot-dependences中定义了版本信息,从而实现了SpringBoot的版本依赖管理;SpringBoot项目在基层了spring-boot-starter-parent在制定了spring-boot-starter-parent的版本信息后,就已经锁定了部分依赖的版本信息;
2. Spring Boot如何通过引入 Starter 引入所有功能相关的依赖
项目中引入的各种starter,在基于POM的依赖传递原理上,在各个依赖底层,打包了多个JAR
以spring-boot-starter-web为里,在 spring-boot-starter-web 中,打包了Web开发场景所需的所有依赖(比如spring-web;spring-mvc;tomcat等),因此,当我们的项目中引入了spring-boot-starter-web后,不在需要引入额外的依赖,就可以实现Web的场景开发了;