Springboot项目中的spring-boot-starter-parent,spring-boot-dependencies依赖关系

Springboot项目中spring-boot-dependencies或spring-boot-parent管理了那些常用的依赖,所以有些不需要加version版本标签了,可以统一项目的依赖,避免后续的版本冲突。而spring-boot-dependencies是spring-boot-starter-parent的父级项目

一、查看springboot版本

1、项目创建初

我们通常使用 Spring Initializer 快速创建SpringBoot项目。系统自动默认选择最新的版本,也可以点击图中Default:https://start.spring.io选择版本(本文中选择2.4.3版本):

如何搭建一个最简单的springboot项目,此处不过多描述。

2、pom文件

以一个简单的springboot工程来查看其pom文件,可以看出父级项目是spring-boot-starter-parent,父级项目可以方便把几个module项目合在一起,减少差异。

【此处pom文件也可以看到我们的版本是2.4.3,行文中均以此版本为例描述】

二、spring-boot-starter-parent,spring-boot-dependencies

1、spring-boot-starter-parent的pom文件

在上面我们已经看到我们springboot的版本,在父级项目的spring-boot-starter-parent定义的,接下来在本地仓库C:\Users\PC.m2\repository\org\springframework\boot\spring-boot-starter-parent\2.4.3找到spring-boot-starter-parent-2.4.3.pom文件,打开发现,==spring-boot-starter-parent的父级项目是spring-boot-dependencies==


2、spring-boot-dependencies的pom文件

接下来查看本地仓库C:\Users\PC.m2\repository\org\springframework\boot\spring-boot-dependencies\2.4.3spring-boot-dependencies-2.4.3.pom

在这里我们看到管理了几百个依赖版本,所以在加入新的依赖的时候,有时发现新加入的依赖不需要<version>标签标出使用的版本就可以,因为spring-boot-dependencies或spring-boot-parent管理了那些常用的依赖,在dependencies里的部分配置可以不用填写version信息,这些version信息会从spring-boot-dependencies里得到继承。

小结eg:通过spring-boot-dependencies-2.4.3.pom文件查看内置的tomcat版本 <tomcat.version>9.0.43</tomcat.version>

spring-boot-dependencies-2.4.3.pom文件内容摘要:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-dependencies</artifactId>
  <version>2.4.3</version>
  <packaging>pom</packaging>
  <name>spring-boot-dependencies</name>
  <description>Spring Boot Dependencies</description>
  <url>https://spring.io/projects/spring-boot</url>
  <licenses>
    <license>
      <name>Apache License, Version 2.0</name>
      <url>https://www.apache.org/licenses/LICENSE-2.0</url>
    </license>
  </licenses>
  <developers>
    <developer>
      <name>Pivotal</name>
      <email>info@pivotal.io</email>
      <organization>Pivotal Software, Inc.</organization>
      <organizationUrl>https://www.spring.io</organizationUrl>
    </developer>
  </developers>
  <scm>
    <url>https://github.com/spring-projects/spring-boot</url>
  </scm>
  <properties>
    <activemq.version>5.16.1</activemq.version>
    <antlr2.version>2.7.7</antlr2.version>
    <appengine-sdk.version>1.9.86</appengine-sdk.version>
    <artemis.version>2.15.0</artemis.version>
    <aspectj.version>1.9.6</aspectj.version>
    <assertj.version>3.18.1</assertj.version>
    <atomikos.version>4.0.6</atomikos.version>
    <awaitility.version>4.0.3</awaitility.version>
    <bitronix.version>2.1.4</bitronix.version>
    <build-helper-maven-plugin.version>3.2.0</build-helper-maven-plugin.version>
    <byte-buddy.version>1.10.20</byte-buddy.version>
    <caffeine.version>2.8.8</caffeine.version>
    <cassandra-driver.version>4.9.0</cassandra-driver.version>
    <classmate.version>1.5.1</classmate.version>
    <commons-codec.version>1.15</commons-codec.version>
    <commons-dbcp2.version>2.8.0</commons-dbcp2.version>
    <commons-lang3.version>3.11</commons-lang3.version>
    <commons-pool.version>1.6</commons-pool.version>
    <commons-pool2.version>2.9.0</commons-pool2.version>
    <couchbase-client.version>3.0.10</couchbase-client.version>
    <db2-jdbc.version>11.5.5.0</db2-jdbc.version>
    <dependency-management-plugin.version>1.0.11.RELEASE</dependency-management-plugin.version>
    <derby.version>10.14.2.0</derby.version>
    <dropwizard-metrics.version>4.1.17</dropwizard-metrics.version>
    <ehcache.version>2.10.6</ehcache.version>
    <ehcache3.version>3.9.0</ehcache3.version>
    <elasticsearch.version>7.9.3</elasticsearch.version>
    <embedded-mongo.version>2.2.0</embedded-mongo.version>
    <flyway.version>7.1.1</flyway.version>
    <freemarker.version>2.3.31</freemarker.version>
    <git-commit-id-plugin.version>3.0.1</git-commit-id-plugin.version>
    <glassfish-el.version>3.0.3</glassfish-el.version>
    <glassfish-jaxb.version>2.3.3</glassfish-jaxb.version>
    <groovy.version>2.5.14</groovy.version>
    <gson.version>2.8.6</gson.version>
    <h2.version>1.4.200</h2.version>
    <hamcrest.version>2.2</hamcrest.version>
    <hazelcast.version>4.0.3</hazelcast.version>
    <hazelcast-hibernate5.version>2.1.1</hazelcast-hibernate5.version>
    <hibernate.version>5.4.28.Final</hibernate.version>
    <hibernate-validator.version>6.1.7.Final</hibernate-validator.version>
    <hikaricp.version>3.4.5</hikaricp.version>
    <hsqldb.version>2.5.1</hsqldb.version>
    <htmlunit.version>2.44.0</htmlunit.version>
    <httpasyncclient.version>4.1.4</httpasyncclient.version>
    <httpclient.version>4.5.13</httpclient.version>
    <httpcore.version>4.4.14</httpcore.version>
    <infinispan.version>11.0.9.Final</infinispan.version>
    <influxdb-java.version>2.20</influxdb-java.version>
    <jackson-bom.version>2.11.4</jackson-bom.version>
    <jakarta-activation.version>1.2.2</jakarta-activation.version>
    <jakarta-annotation.version>1.3.5</jakarta-annotation.version>
    <jakarta-jms.version>2.0.3</jakarta-jms.version>
    <jakarta-json.version>1.1.6</jakarta-json.version>
    <jakarta-json-bind.version>1.0.2</jakarta-json-bind.version>
    <jakarta-mail.version>1.6.5</jakarta-mail.version>
    <jakarta-persistence.version>2.2.3</jakarta-persistence.version>
    <jakarta-servlet.version>4.0.4</jakarta-servlet.version>
    <jakarta-servlet-jsp-jstl.version>1.2.7</jakarta-servlet-jsp-jstl.version>
    <jakarta-transaction.version>1.3.3</jakarta-transaction.version>
    <jakarta-validation.version>2.0.2</jakarta-validation.version>
    <jakarta-websocket.version>1.1.2</jakarta-websocket.version>
    <jakarta-ws-rs.version>2.1.6</jakarta-ws-rs.version>
    <jakarta-xml-bind.version>2.3.3</jakarta-xml-bind.version>
    <jakarta-xml-soap.version>1.4.2</jakarta-xml-soap.version>
    <jakarta-xml-ws.version>2.3.3</jakarta-xml-ws.version>
    <janino.version>3.1.3</janino.version>
    <javax-activation.version>1.2.0</javax-activation.version>
    <javax-annotation.version>1.3.2</javax-annotation.version>
    <javax-cache.version>1.1.1</javax-cache.version>
    <javax-jaxb.version>2.3.1</javax-jaxb.version>
    <javax-jaxws.version>2.3.1</javax-jaxws.version>
    <javax-jms.version>2.0.1</javax-jms.version>
    <javax-json.version>1.1.4</javax-json.version>
    <javax-jsonb.version>1.0</javax-jsonb.version>
    <javax-mail.version>1.6.2</javax-mail.version>
    <javax-money.version>1.1</javax-money.version>
    <javax-persistence.version>2.2</javax-persistence.version>
    <javax-transaction.version>1.3</javax-transaction.version>
    <javax-validation.version>2.0.1.Final</javax-validation.version>
    <javax-websocket.version>1.1</javax-websocket.version>
    <jaxen.version>1.2.0</jaxen.version>
    <jaybird.version>3.0.10</jaybird.version>
    <jboss-logging.version>3.4.1.Final</jboss-logging.version>
    <jboss-transaction-spi.version>7.6.0.Final</jboss-transaction-spi.version>
    <jdom2.version>2.0.6</jdom2.version>
    <jedis.version>3.3.0</jedis.version>
    <jersey.version>2.32</jersey.version>
    <jetty-el.version>8.5.54</jetty-el.version>
    <jetty-jsp.version>2.2.0.v201112011158</jetty-jsp.version>
    <jetty-reactive-httpclient.version>1.1.5</jetty-reactive-httpclient.version>
    <jetty.version>9.4.36.v20210114</jetty.version>
    <jmustache.version>1.15</jmustache.version>
    <johnzon.version>1.2.10</johnzon.version>
    <jolokia.version>1.6.2</jolokia.version>
    <jooq.version>3.14.7</jooq.version>
    <json-path.version>2.4.0</json-path.version>
    <json-smart.version>2.3</json-smart.version>
    <jsonassert.version>1.5.0</jsonassert.version>
    <jstl.version>1.2</jstl.version>
    <jtds.version>1.3.1</jtds.version>
    <junit.version>4.13.2</junit.version>
    <junit-jupiter.version>5.7.1</junit-jupiter.version>
    <kafka.version>2.6.0</kafka.version>
    <kotlin.version>1.4.30</kotlin.version>
    <kotlin-coroutines.version>1.4.2</kotlin-coroutines.version>
    <lettuce.version>6.0.2.RELEASE</lettuce.version>
    <liquibase.version>3.10.3</liquibase.version>
    <log4j2.version>2.13.3</log4j2.version>
    <logback.version>1.2.3</logback.version>
    <lombok.version>1.18.18</lombok.version>
    <mariadb.version>2.7.2</mariadb.version>
    <maven-antrun-plugin.version>1.8</maven-antrun-plugin.version>
    <maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
    <maven-clean-plugin.version>3.1.0</maven-clean-plugin.version>
    <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
    <maven-dependency-plugin.version>3.1.2</maven-dependency-plugin.version>
    <maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version>
    <maven-enforcer-plugin.version>3.0.0-M3</maven-enforcer-plugin.version>
    <maven-failsafe-plugin.version>2.22.2</maven-failsafe-plugin.version>
    <maven-help-plugin.version>3.2.0</maven-help-plugin.version>
    <maven-install-plugin.version>2.5.2</maven-install-plugin.version>
    <maven-invoker-plugin.version>3.2.1</maven-invoker-plugin.version>
    <maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
    <maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>
    <maven-resources-plugin.version>3.2.0</maven-resources-plugin.version>
    <maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
    <maven-source-plugin.version>3.2.1</maven-source-plugin.version>
    <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
    <maven-war-plugin.version>3.3.1</maven-war-plugin.version>
    <micrometer.version>1.6.4</micrometer.version>
    <mimepull.version>1.9.13</mimepull.version>
    <mockito.version>3.6.28</mockito.version>
    <mongodb.version>4.1.1</mongodb.version>
    <mssql-jdbc.version>8.4.1.jre8</mssql-jdbc.version>
    <mysql.version>8.0.23</mysql.version>
    <nekohtml.version>1.9.22</nekohtml.version>
    <neo4j-java-driver.version>4.1.1</neo4j-java-driver.version>
    <netty.version>4.1.59.Final</netty.version>
    <netty-tcnative.version>2.0.36.Final</netty-tcnative.version>
    <oauth2-oidc-sdk.version>8.36</oauth2-oidc-sdk.version>
    <nimbus-jose-jwt.version>8.20.2</nimbus-jose-jwt.version>
    <ojdbc.version>19.3.0.0</ojdbc.version>
    <okhttp3.version>3.14.9</okhttp3.version>
    <oracle-database.version>19.8.0.0</oracle-database.version>
    <pooled-jms.version>1.2.1</pooled-jms.version>
    <postgresql.version>42.2.18</postgresql.version>
    <prometheus-pushgateway.version>0.9.0</prometheus-pushgateway.version>
    <quartz.version>2.3.2</quartz.version>
    <querydsl.version>4.4.0</querydsl.version>
    <r2dbc-bom.version>Arabba-SR8</r2dbc-bom.version>
    <rabbit-amqp-client.version>5.10.0</rabbit-amqp-client.version>
    <reactive-streams.version>1.0.3</reactive-streams.version>
    <reactor-bom.version>2020.0.4</reactor-bom.version>
    <rest-assured.version>3.3.0</rest-assured.version>
    <rsocket.version>1.1.0</rsocket.version>
    <rxjava.version>1.3.8</rxjava.version>
    <rxjava-adapter.version>1.2.1</rxjava-adapter.version>
    <rxjava2.version>2.2.21</rxjava2.version>
    <saaj-impl.version>1.5.2</saaj-impl.version>
    <selenium.version>3.141.59</selenium.version>
    <selenium-htmlunit.version>2.44.0</selenium-htmlunit.version>
    <sendgrid.version>4.6.8</sendgrid.version>
    <servlet-api.version>4.0.1</servlet-api.version>
    <slf4j.version>1.7.30</slf4j.version>
    <snakeyaml.version>1.27</snakeyaml.version>
    <solr.version>8.5.2</solr.version>
    <spring-amqp.version>2.3.5</spring-amqp.version>
    <spring-batch.version>4.3.1</spring-batch.version>
    <spring-data-bom.version>2020.0.5</spring-data-bom.version>
    <spring-framework.version>5.3.4</spring-framework.version>
    <spring-hateoas.version>1.2.4</spring-hateoas.version>
    <spring-integration.version>5.4.4</spring-integration.version>
    <spring-kafka.version>2.6.6</spring-kafka.version>
    <spring-ldap.version>2.3.3.RELEASE</spring-ldap.version>
    <spring-restdocs.version>2.0.5.RELEASE</spring-restdocs.version>
    <spring-retry.version>1.3.1</spring-retry.version>
    <spring-security.version>5.4.5</spring-security.version>
    <spring-session-bom.version>2020.0.3</spring-session-bom.version>
    <spring-ws.version>3.0.10.RELEASE</spring-ws.version>
    <sqlite-jdbc.version>3.32.3.3</sqlite-jdbc.version>
    <sun-mail.version>1.6.5</sun-mail.version>
    <thymeleaf.version>3.0.12.RELEASE</thymeleaf.version>
    <thymeleaf-extras-data-attribute.version>2.0.1</thymeleaf-extras-data-attribute.version>
    <thymeleaf-extras-java8time.version>3.0.4.RELEASE</thymeleaf-extras-java8time.version>
    <thymeleaf-extras-springsecurity.version>3.0.4.RELEASE</thymeleaf-extras-springsecurity.version>
    <thymeleaf-layout-dialect.version>2.5.2</thymeleaf-layout-dialect.version>
    <tomcat.version>9.0.43</tomcat.version>
    <unboundid-ldapsdk.version>4.0.14</unboundid-ldapsdk.version>
    <undertow.version>2.2.4.Final</undertow.version>
    <versions-maven-plugin.version>2.8.1</versions-maven-plugin.version>
    <webjars-hal-browser.version>3325375</webjars-hal-browser.version>
    <webjars-locator-core.version>0.46</webjars-locator-core.version>
    <wsdl4j.version>1.6.3</wsdl4j.version>
    <xml-maven-plugin.version>1.0.2</xml-maven-plugin.version>
    <xmlunit2.version>2.7.0</xmlunit2.version>
  </properties>
  <...此处还有好多参看源文件....>
  </build>
</project>

三、使用springboot两种方式区别:

我们知道pring-boot-dependencies是spring-boot-starter-parent的父级项目,而这两个都是使用springboot的方式,区别是:

  • spring-boot-starter-parent。由于maven单继承,再想继承别的module就不可能了,而实际开发中,用户很可能需要继承自己公司的标准parent配置,这时就需要下边第二种。
  • spring-boot-dependencies。在dependencyManagement中使用scope=import的方式来保持依赖项管理。这种方式解决了多继承,同样也让父类中的dependency是分类,不会那么乱。

接下来我们特别的描述下第二种使用父级别的pring-boot-dependencies配置,eg:

<dependencyManagement>
        <dependencies>
            <dependency>
               <!--不使用parent方式进行依赖,需要scope和type设置-->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.1.6.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

springboot官网中相关描述如下可参考:
https://docs.spring.io/spring-boot/docs/2.0.2.RELEASE/reference/htmlsingle/#boot-documentation

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,142评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,298评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,068评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,081评论 1 291
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,099评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,071评论 1 295
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,990评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,832评论 0 273
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,274评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,488评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,649评论 1 347
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,378评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,979评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,625评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,796评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,643评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,545评论 2 352

推荐阅读更多精彩内容