解決jar包依賴:Spring IO platform推出bom

名詞解釋:
BOM(bill of materials):材料清單,用於解決jar包依賴的好方法。

Spring IO Platform

緣起:Spring起初只專注ioc和aop,現在已發展成一個龐大體系。比如security、mvc等。如此一來,不同模塊或者與外部進行集成時,依賴處理就需要各自對應版本號。比如,較新spring與較老的quartz,它們集成就會遇到問題,給搭建和升級帶來不便。因此Spring IO Platform應運而生,只要項目中引入了它,外部集成時依賴關係無需版本號。官網的原文如下:“when you do declare a dependency on something that’s part of the Platform, you will now be able to omit the version number.”
舉例如下:

<dependencies>
    <dependency> 
        <groupId>org.springframework</groupId> 
    </dependency>
</dependencies>

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

Spring相關的BOM

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

對於Spring工程來說,直接在pom.xml文件中添加如下配置代碼,即可免去管理版本衝突的難題。

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <version>4.2.0.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.3.0.M2</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>io.spring.platform</groupId>
            <artifactId>platform-bom</artifactId>
            <version>1.1.3.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

參考文章

  1. Introduction to spring io platform
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章