Spring 4.3.3和Spring Data JPA 1.10.4冲突Spring版本

时间:2017-01-27 02:53:04

标签: spring spring-data

我们有Spring版本4.3.3和Spring Data JPA版本1.10.4 根据客户端技术架构师的说法,Spring Data JPA 1.10.4版依赖于Spring 4.2.8。 因此,我们在maven依赖项中有两个版本的Spring,声明的版本是4.3.3,而Spring数据是Spring版本4.2.8。 因此,我们在Spring Data JPA中排除了Spring核心和其他Spring库,如下所示:

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-jpa</artifactId>
    <version>1.10.4.RELEASE</version>
    <exclusions>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-asm</artifactId>
        </exclusion>                           
        <exclusion>
             <groupId>org.springframework</groupId>
             <artifactId>spring-beans</artifactId>
         </exclusion>                           
         <exclusion>
             <groupId>org.springframework</groupId>
             <artifactId>spring-context</artifactId>
         </exclusion>
         <exclusion>
              <groupId>org.springframework</groupId>
              <artifactId>spring-tx</artifactId>
         </exclusion>
         <exclusion>
               <groupId>org.springframework</groupId>
               <artifactId>spring-core</artifactId>
         </exclusion>
         <exclusion>
               <groupId>org.springframework</groupId>
               <artifactId>spring-aop</artifactId>
         </exclusion>                           
    </exclusions>
</dependency>

有了这个,Spring版本中是否会再发生冲突?

1 个答案:

答案 0 :(得分:0)

为了避免Spring依赖项中的冲突,我强烈建议使用Spring BoM(Bill of Materials)功能

https://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#overview-maven-bom

  

可能会意外混合不同版本的Spring JAR   使用Maven时。例如,您可能会发现第三方   库,或另一个Spring项目,引入了传递依赖   到较旧版本。如果您忘记明确声明直接   依赖自己,可能出现各种意想不到的问题。

     

为了克服这些问题,Maven支持“法案”的概念   材料“(BOM)依赖。您可以导入spring-framework-bom   在您的dependencyManagement部分确保所有spring   依赖项(直接和传递)属于同一版本。

http://docs.spring.io/spring-data/jpa/docs/1.11.0.RELEASE/reference/html/#dependencies

你的Pom看起来就像下面那样改变版本:

<dependencies>

    <!-- DECLARE ALL SPRING DEPENDENCIES WITHOUT VERSIONS 
         AS RESOLVED FROM BoM
    -->

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-rest-webmvc</artifactId>
    </dependency>

    <!-- OTHER SPRING DEPENDENCIES AS REQUIRED -->
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-framework-bom</artifactId>
            <type>pom</type>
            <version>4.2.6.RELEASE</version>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-bom</artifactId>
            <type>pom</type>
            <version>4.0.4.RELEASE</version>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-releasetrain</artifactId>
            <version>Hopper-SR3</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    <dependencies>
</dependencyManagement>