1. 程式人生 > >spring maven項目解決依賴jar包版本沖突方案

spring maven項目解決依賴jar包版本沖突方案

acc ans ng- amp 解決方案 depend pri expected zhong

引入:http://blog.csdn.net/sanzhongguren/article/details/71191290

在spring reference中提到一個解決spring jar包之間版本沖突的解決方案,原文如下

It is possible to accidentally mix different versions of Spring JARs when using Maven. For example, you may find that a third-party library, or another Spring project, pulls in a transitive dependency to an older release. If you forget to explicitly declare a direct dependency yourself, all sorts of unexpected issues can arise.

To overcome such problems Maven supports the concept of a "bill of materials" (BOM) dependency. You can import the spring-framework-bom in yourdependencyManagement section to ensure that all spring dependencies (both direct and transitive) are at the same version.

在配置spring項目依賴時可以通過引入spring-framework-bom避免項目中的spring jar包及關聯依賴的三方jar包之間的版本沖突,引入方式:

<dependencyManagement>  
    <dependencies>  
        <dependency>  
            <groupId>org.springframework</groupId>  
            <artifactId>spring-framework-bom</artifactId>  
            <version>4.1.3.RELEASE</version>  
            <type
>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>

引入後的另一個好處就是在pom文件中引入spring相關依賴時不用再聲明<version>屬性,以後直接像下邊這樣聲明就可以了:

<dependencies>  
    <dependency>  
        <groupId>org.springframework</groupId>  
        <artifactId>spring-context</artifactId>  
    </dependency>  
    <dependency>  
        <groupId>org.springframework</groupId>  
        <artifactId>spring-web</artifactId>  
    </dependency>  
<dependencies>  

PS: Spring官方reference網址 http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/
還有就是最近找到一個翻譯reference的網址,雖然沒有翻譯完整有興趣的也可以看看 http://spring.cndocs.tk/

spring maven項目解決依賴jar包版本沖突方案