spring-boot-starter-parent 与 spring-boot-dependencies的关系

Spring Boot的每个发布版本都会规划它所支持的依赖项。实际上,你不用指定这些依赖项的版本号,因为Spring Boot都为你管理好了。当更新Spring Boot时,会相应的更新依赖。

spring-cloud-dependencies也是一个依赖管理器的pom文件,与spring-boot-starter-parent的作用一样,不同的是spring-cloud-dependencies是对cloud的依赖管理。如:spring-cloud-starter-config、spring-cloud-starter-netflix-eureka-server。

构建SpringBoot项目有两种方式:

(1)第一种是继承spring-boot-starter-parent 

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.5.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>

(2)【常用、推荐】第二种是通过dependencyManagement进行依赖管理

 一般情况下,企业都有自己的parent依赖包,然后所有的项目都必须继承对应的parent包,这时候,我们就可以通过这种方式使用springboot,使用这种方式记得指定maven编译版本.

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring-boot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

这两种方式,我们在使用spring-boot-starter的时候都不需要指定版本; 

继承spring-boot-starter-parent其实也算是继承自spring-boot-dependencies,我们点开spring-boot-starter-parent,可以看到parent其实也是继承dependencies,parent里面就增加了一些插件,然后指定了maven编译版本:

 

posted @ 2022-01-17 21:28  残城碎梦  阅读(797)  评论(0编辑  收藏  举报