傳統咱們搭建SSM項目的時候,使用maven作jar依賴管理的時候,還須要咱們配置依賴jar包相應的版本,而且構建項目的時候,是須要什麼jar包就導入什麼jar包,並未對jar進行系統的歸結和管理。而springboot改變了這一現狀,他至關於對maven依賴上進行更爲全面的歸結和管理。html
官網中也說明了springboot依賴管理:web
Each release of Spring Boot provides a curated list of dependencies that it supports. In practice, you do not need to provide a version for any of these dependencies in your build configuration, as Spring Boot manages that for you. When you upgrade Spring Boot itself, these dependencies are upgraded as well in a consistent way,The curated list contains all the spring modules that you can use with Spring Boot as well as a refined list of third party libraries.spring
上述解釋是:每個SpringBoot版本都提供了一個它所支持的依賴關係的管理列表。實際上,您不須要在構建配置中爲這些依賴項中的任何一個提供版本,由於Spring引導會爲您管理這個版本。當您升級Spring引導自己時,這些依賴項也會以一致的方式升級,管理列表包含全部能夠與Spring引導一塊兒使用的Spring模塊,以及第三方庫的優化列表。springboot
當用maven來做項目依賴管理的時候,咱們能夠在pom.xml文件中看到以下配置:app
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
它引入spring-boot-starter-parent父項目,我們能夠繼續看spring-boot-starter-parent項目有哪些依賴,咱們能夠在idea工具中,使用ctrl能夠直接進入到項目依賴pom文件中(點擊spring-boot-starter-parent):框架
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.1.4.RELEASE</version> <relativePath>../../spring-boot-dependencies</relativePath> </parent>
它是繼續依賴spring-boot-dependencies這個項目,一樣的方式進入到spring-boot-dependencies項目POM文件中,主要看properties屬性和dependencyManagement屬性:maven
<properties> <activemq.version>5.15.9</activemq.version> <antlr2.version>2.7.7</antlr2.version> <appengine-sdk.version>1.9.73</appengine-sdk.version> <artemis.version>2.6.4</artemis.version> <aspectj.version>1.9.2</aspectj.version> <assertj.version>3.11.1</assertj.version> <atomikos.version>4.0.6</atomikos.version> <bitronix.version>2.1.4</bitronix.version> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot</artifactId> <version>2.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-test</artifactId> <version>2.1.4.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-test-autoconfigure</artifactId> <version>2.1.4.RELEASE</version> </dependency> 由於內容較多我只列舉其中的一部份內容
從POM文件中能夠看到spring-boot-dependencies項目的POM文件纔是真正管理springboot項目依賴的。他至關於jar包的依賴仲裁,他提供了jar包的版本管理,以及spring框架和其餘第三方組件jar包的依賴管理。ide
使用這種依賴管理包括兩種方式:spring-boot
1.(默認方式)繼承Spring Boot的提供的父工程,須要在pom.xml中配置,以下: 工具
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
2. 經過scope=import的方式引入, 在不少時候咱們須要繼承自有的父工程或因爲其餘設置沒法使用Spring Boot提供的父工程。此時能夠經過scope=import的方式進行引入,以下:
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.1.4.BUILD-SNAPSHOT</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
此處經過scope=import的方式導入了依賴的管理配置。但此時咱們沒法經過在properties中覆蓋對應的屬性來完成version的控制(由於沒有繼承父工程)。以此應對的方式是經過在dependencyManagement中進行配置,而且要求在spring-boot-dependencies以前添加便可。同時,對應spring-boot-maven-plugin插件也須要顯式配置才能夠。
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
Starters是一組方便的依賴性描述符,能夠包括在應用程序中。您能夠爲全部Spring和您須要的相關技術組件提供一站式服務,好比「spring-boot-starter-web」,它幫咱們導入web模塊正常運行所依賴的組件jar包。springboot提供了多種場景啓動器,咱們能夠參照文檔查看各類啓動器如何導入和使用,以及相關的jar依賴,相關連接。全部的啓動器都遵循相似的命名模式;「spring-boot-starter-*」,其中*是特定類型的應用程序。