【问题标题】:Using Spring 4.0 with spring-data-jpa将 Spring 4.0 与 spring-data-jpa 一起使用
【发布时间】:2014-03-10 11:12:28
【问题描述】:

我在我的 JavaEE 应用程序中使用 Spring 4.0,并尝试使用 Spring-data-jpa。

但是当我添加 Spring-data-jpa 依赖时,我发现 Spring-data-jpa 将依赖 Spring-3.x。

那我想知道这会引起什么问题吗?因为我的应用程序将有 Spring-4.x 和 Spring-3.x。

有人有同样的经历吗?


更新:

我正在使用 Spring-data-jpg-1.4.3:

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>1.4.3.RELEASE</version>
    </dependency>

但是当我运行mvn dependency:tree 时,我得到了这个:

+- org.springframework:spring-context:jar:4.0.0.RELEASE:compile
|  +- org.springframework:spring-beans:jar:4.0.0.RELEASE:compile
|  +- org.springframework:spring-core:jar:4.0.0.RELEASE:compile
|  |  \- commons-logging:commons-logging:jar:1.1.1:compile
|  \- org.springframework:spring-expression:jar:4.0.0.RELEASE:compile
+- org.springframework:spring-aop:jar:4.0.0.RELEASE:compile
|  \- aopalliance:aopalliance:jar:1.0:compile
+- org.springframework.data:spring-data-jpa:jar:1.4.3.RELEASE:compile
|  +- org.springframework.data:spring-data-commons:jar:1.6.3.RELEASE:compile
|  +- org.springframework:spring-orm:jar:3.1.4.RELEASE:compile
|  |  \- org.springframework:spring-jdbc:jar:3.1.4.RELEASE:compile
|  +- org.springframework:spring-tx:jar:3.1.4.RELEASE:compile
|  +- org.aspectj:aspectjrt:jar:1.7.2:compile
|  +- org.slf4j:slf4j-api:jar:1.7.1:compile
|  \- org.slf4j:jcl-over-slf4j:jar:1.7.1:runtime
+- org.aspectj:aspectjweaver:jar:1.7.4:compile
+- org.springframework:spring-test:jar:4.0.0.RELEASE:test

好像spring 4.0..和spring 3.1.4..混在一起了..

【问题讨论】:

  • 永远不要混合等待发生的麻烦的弹簧版本。 Spring data 1.4.x 分支应该可以在 Spring 4 中正常工作。
  • @M.Deinum:我更新了我的帖子。

标签: spring spring-data-jpa


【解决方案1】:

这是 spring-data-jpa 1.4.3.RELEASE pom denepdency 中的错误。
实际发生的是它加载了这个 maven pom 中存在的 spring 依赖项,而不是您要导入的那些。
简短的回答是将其作为父项添加到您的 Maven 项目中:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.0.0.RC5</version>
</parent>

以便它可以继承正确的依赖关系。

解决这个问题的另一种方法是使用&lt;exclusions&gt; 标签来排除它们,然后导入正确的依赖项,但这需要更多时间并且不那么干净。如果您不想添加 spring-boot-start-parent,那么这就是解决此错误的方法。

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-mongodb</artifactId>
    <version>1.4.1.RELEASE</version>
    <exclusions>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
        </exclusion>
        <exclusion>
         ...
        </exclusion> 
    </exclusions>
</dependency>

有关详细信息,请参阅 here

【讨论】:

    猜你喜欢
    • 2014-10-21
    • 1970-01-01
    • 1970-01-01
    • 2017-08-26
    • 2019-03-07
    • 1970-01-01
    • 2014-07-29
    • 2013-03-05
    • 2019-02-09
    相关资源
    最近更新 更多