Spring Boot依賴
使用Spring Boot很簡單,先添加基礎依賴包,有以下兩種方式
1.繼承spring-boot-starter-parent項目
-
<parent> -
<groupId>org.springframework.boot</groupId> -
<artifactId>spring-boot-starter-parent</artifactId> -
<version>1.5.6.RELEASE</version> -
</parent>
2.引入spring-boot-dependencies項目依賴
-
<dependencyManagement> -
<dependencies> -
<dependency> -
<groupId>org.springframework.boot</groupId> -
<artifactId>spring-boot-dependencies</artifactId> -
<version>1.5.6.RELEASE</version> -
<type>pom</type> -
<scope>import</scope> -
</dependency> -
</dependencyManagement>
Spring Boot依賴注意點
1.屬性覆蓋只對繼承有效
僅當您的Maven項目(直接或間接)繼承自spring-boot-dependencies時,此方法才有效。如果您在自己的dependencyManagement部分中添加了spring-boot-dependencies,進口您必須自己重新定義工件,而不是覆蓋屬性。
Spring Boot依賴包裡面的組件的版本都是和當前Spring Boot綁定的,如果要修改裡面組件的版本,只需要添加以下屬性覆蓋即可,但這種方式只對繼承有效,導入的方式無效。
-
<properties> -
<slf4j.version>1.7.25<slf4j.version> -
</properties>
如果引入的方式要實現版本的升級,達到上面的效果,這樣也可以做到,把要升級的組件依賴放到Spring Boot之前。
-
<dependencyManagement> -
<dependencies> -
<!-- Override Spring Data release train provided by Spring Boot --> -
<dependency> -
<groupId>org.springframework.data</groupId> -
<artifactId>spring-data-releasetrain</artifactId> -
<version>Fowler-SR2</version> -
<scope>import</scope> -
<type>pom</type> -
</dependency> -
<dependency> -
<groupId>org.springframework.boot</groupId> -
<artifactId>spring-boot-dependencies</artifactId> -
<version>1.5.6.RELEASE</version> -
<type>pom</type> -
<scope>import</scope> -
</dependency> -
</dependencies> -
</dependencyManagement>
每個Spring Boot版本都是針對一組特定的第三方依賴項進行設計和測試的。覆蓋版本可能會導致兼容性問題。
需要注意,要修改Spring Boot的依賴組件版本可能會造成不兼容的問題。