參考文章:
https://blog.csdn.net/blueheart20/article/details/81011805
在Maven項目中,不同的第三方依賴包可以直接或者間接依賴於Spring,這些Spring的版本各有不同,則在項目中容易產生版本的沖突。
Spring不同模塊或者與外部進行集成時,依賴處理就需要各自對應版本號。它們的集成經常會遇到問題,給搭建和升級帶來不便。
BOM是由Maven提供的功能,用以統一間接或者直接依賴的類庫版本,強制某個類庫使用某一個統一的版本。SpringSource為了解決這些Jar沖突,推出了各種BOM,最著名的就是spring platform io bom,其中最核心的三個是:spring-framework-bom、spring-boot-dependencies、platform-bom。
在maven的pom.xml中無需指定具體的類庫版本,直接使用,即默認使用bom中指定的版本。
# 項目中可以這么用
<properties>
<spring.version>5.3.10</spring.version>
<spring.boot.version>2.5.5</spring.boot.version>
<spring.platform.version>Cairo-SR8</spring.platform.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-framework-bom -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${spring.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--一般項目用上面這個進行管理jar包就行了 下面的是boot項目使用的-->
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.3.0.M2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.spring.platform/platform-bom -->
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>${spring.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>