欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

解析spring-boot-starter-parent简介

程序员文章站 2024-03-07 11:12:15
本指南将帮助您了解spring boot starter parent如何帮助管理依赖项版本,所有spring boot项目通常使用spring-boot-starter-...

本指南将帮助您了解spring boot starter parent如何帮助管理依赖项版本,所有spring boot项目通常使用spring-boot-starter-parent作为pom.xml中的父项:

<parent>
    <groupid>org.springframework.boot</groupid>
    <artifactid>spring-boot-starter-parent</artifactid>
    <version>1.4.0.release</version>
  </parent>

parent poms为多个子项目和模块管理以下内容:

  • 配置 - java版本和其他属性
  • depedency management - 依赖项的版本
  • 默认插件配置

内部原理

首先 启动器spring boot starter parent将spring-boot-dependencies定义为父pom。它从spring-boot-dependencies继承了依赖关系管理。

<parent>
  <groupid>org.springframework.boot</groupid>
  <artifactid>spring-boot-dependencies</artifactid>
  <version>1.4.0.release</version>
  <relativepath>../../spring-boot-dependencies</relativepath>
</parent>

默认的java版本是1.6。项目可以通过<java.version>1.8</java.version>在项目pom中指定属性来覆盖它。还有一些与编码和源相关的其他设置,目标版本也在父pom中设置。

<java.version>1.6</java.version>
<resource.delimiter>@</resource.delimiter> <!-- delimiter that doesn't * with spring ${} placeholders -->
<project.build.sourceencoding>utf-8</project.build.sourceencoding>
<project.reporting.outputencoding>utf-8</project.reporting.outputencoding>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>

spring boot starter parent指定了一系列插件的默认配置,包括maven-failsafe-plugin,maven-jar-plugin和maven-surefire-plugin。

<plugin>
  <groupid>org.apache.maven.plugins</groupid>
  <artifactid>maven-failsafe-plugin</artifactid>
  <executions>
   <execution>
     <goals>
      <goal>integration-test</goal>
      <goal>verify</goal>
     </goals>
   </execution>
  </executions>
</plugin>
<plugin>
  <groupid>org.apache.maven.plugins</groupid>
  <artifactid>maven-jar-plugin</artifactid>
  <configuration>
   <archive>
     <manifest>
      <mainclass>${start-class}</mainclass>
      <adddefaultimplementationentries>true</adddefaultimplementationentries>
     </manifest>
   </archive>
  </configuration>
</plugin>
<plugin>
  <groupid>org.apache.maven.plugins</groupid>
  <artifactid>maven-surefire-plugin</artifactid>
  <configuration>
   <includes>
     <include>**/*tests.java</include>
     <include>**/*test.java</include>
   </includes>
   <excludes>
     <exclude>**/abstract*.java</exclude>
   </excludes>
  </configuration>
</plugin>

spring boot starter parent从spring-boot-dependencies继承了什么?

spring boot dependencies定义了所有spring boot项目的默认依赖关系管理。如果我们想要使用特定依赖项的新版本,我们可以通过在项目pom中指定新属性来覆盖该版本。下面的摘录显示了由spring boot dependencies父pom管理的一些重要依赖项。由于spring boot starter parent继承自spring-boot-dependencies,因此它也共享所有这些特性。

<properties>
  <activemq.version>5.13.4</activemq.version>
     ...
  <ehcache.version>2.10.2.2.21</ehcache.version>
  <ehcache3.version>3.1.1</ehcache3.version>
     ...
  <h2.version>1.4.192</h2.version>
  <hamcrest.version>1.3</hamcrest.version>
  <hazelcast.version>3.6.4</hazelcast.version>
  <hibernate.version>5.0.9.final</hibernate.version>
  <hibernate-validator.version>5.2.4.final</hibernate-validator.version>
  <hikaricp.version>2.4.7</hikaricp.version>
  <hikaricp-java6.version>2.3.13</hikaricp-java6.version>
  <hornetq.version>2.4.7.final</hornetq.version>
  <hsqldb.version>2.3.3</hsqldb.version>
  <htmlunit.version>2.21</htmlunit.version>
  <httpasyncclient.version>4.1.2</httpasyncclient.version>
  <httpclient.version>4.5.2</httpclient.version>
  <httpcore.version>4.4.5</httpcore.version>
  <infinispan.version>8.2.2.final</infinispan.version>
  <jackson.version>2.8.1</jackson.version>
     ....
  <jersey.version>2.23.1</jersey.version>
  <jest.version>2.0.3</jest.version>
  <jetty.version>9.3.11.v20160721</jetty.version>
  <jetty-jsp.version>2.2.0.v201112011158</jetty-jsp.version>
  <spring-security.version>4.1.1.release</spring-security.version>
  <tomcat.version>8.5.4</tomcat.version>
  <undertow.version>1.3.23.final</undertow.version>
  <velocity.version>1.7</velocity.version>
  <velocity-tools.version>2.0</velocity-tools.version>
  <webjars-hal-browser.version>9f96c74</webjars-hal-browser.version>
  <webjars-locator.version>0.32</webjars-locator.version>
  <wsdl4j.version>1.6.3</wsdl4j.version>
  <xml-apis.version>1.4.01</xml-apis.version>
</properties>

将maven 3.2.1定义为所需的最低版本:

<prerequisites>
  <maven>3.2.1</maven>
</prerequisites>

spring boot

总结

以上所述是小编给大家介绍的spring-boot-starter-parent简介,希望对大家有所帮助