1. 程式人生 > >Spring相關的BOM,有效解決不同模組依賴版本問題

Spring相關的BOM,有效解決不同模組依賴版本問題

Spring起初只專注ioc和aop,現在已發展成一個龐大體系。比如security、mvc等。如此一來,不同模組或者與外部進行整合時,依賴處理就需要各自對應版本號。比如,較新spring與較老的quartz,它們整合就會遇到問題,給搭建和升級帶來不便。因此Spring IO Platform應運而生,只要專案中引入了它,外部整合時依賴關係無需版本號。

當然SpringSource為了解決這些Jar衝突,推出了各種BOM,當然最著名的就是spring platform io bom,其中最核心的三個是:spring-framework-bom、spring-boot-dependencies、platform-bom。


Spring IO Platform只是一個pom檔案,記錄了spring與其他開源專案對應的版本。省去了版本號,也就省去了處理依賴時的問題,因為Spring IO Platform中有最優的版本配置。

對於Spring工程來說,直接在pom.xml檔案中新增如下配置程式碼,即可免去管理版本衝突的難題。

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <version>4.3.12.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.5.8.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>io.spring.platform</groupId>
            <artifactId>platform-bom</artifactId>
            <version>2.0.8.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>