📜  Spring Boot – Starter Parent

📅  最后修改于: 2022-05-13 01:54:39.886000             🧑  作者: Mango

Spring Boot – Starter Parent

Spring Boot Starter Parent 是一个启动项目,为基于 spring 的应用程序提供默认配置。它作为父项添加到 pom.xml 文件中。 spring-boot-starter-parentspring-boot-dependencies定义为其父级。 spring-boot-starter-parent继承了spring-boot-dependencies 的依赖管理。每个 Spring Boot 版本都提供了一个依赖项列表以及它支持的最新版本。 starter parent 的依赖管理特性允许公共依赖省略 pom.xml 文件中的标签。如果依赖项需要一个特定版本而不是 starter parent 配置的版本,则可以使用标签添加。以下是启动父项目的特点:

  • 依赖项管理功能管理常见依赖项的版本。
  • 提供默认编译器级别作为Java 1.8 和 UTF-8 源编码。
  • 为 Maven 插件提供默认配置,例如 maven-surefire-plugin、maven-jar-plugin 和 maven-failsafe-plugin。
  • 使用重新打包执行 id执行重新打包目标。
  • 资源过滤和配置特定于配置文件的文件。

spring-boot-starter-parent 的父级如下所示


    org.springframework.boot
    spring-boot-dependencies
    2.1.0.RELEASE
    ../../spring-boot-dependencies

必须在 pom.xml 中添加以下代码才能使用spring-boot-starter-parent作为父项目。


    org.springframework.boot
    spring-boot-starter-parent
    2.5.2 
     

管理依赖

任何 spring boot starter 都可以包含在依赖项部分下。如果我们省略特定启动器的版本,Maven 将根据部分中定义的版本号下载 jar 文件。例如,如果我们需要一个数据访问层,那么我们应该在 pom.xml 文件中添加spring-data-jpa依赖启动器。




  
    org.springframework.data
    spring-data-jpa
  

依赖管理标签

如果您需要spring-boot-starter-parent提供的不同版本的依赖项,我们可以在标记中添加特定版本,并在dependencyManagement部分中包含依赖项及其版本。


    
        
            org.springframework.boot
            spring-boot-starter-web
            2.4.0
        
    

特性

我们知道spring-boot-starter-parent使用其中定义的属性来配置Java编译器版本、Maven 插件版本和依赖项版本。我们可以在属性部分下的 pom.xml 文件中覆盖这些属性值。假设我们的项目需要不同版本的sl4j库和不同的Java版本。


    1.8
    1.7.30

在没有 Starter Parent 的情况下使用 Spring Boot

如果我们想从自定义的父POM继承或者手动定义所有Maven配置,我们不从spring-boot-starter-parent pom继承。但是,我们仍然可以从spring-boot-dependencies提供的依赖项管理功能(而不是插件管理)中受益,通过将依赖项包含在dependencyMangement部分中作为导入范围。


    
        
            
            org.springframework.boot
            spring-boot-dependencies
            2.5.2
            pom
            import