java - 在 Spring 3.1.0 中使用 Spring Data JPA

标签 java spring maven spring-data-jpa

有人知道如何使用 Spring Data JPA 和 Spring 3.1.0/3.1.1 吗?

Spring Data JPA 1.0.3 依赖于 spring 3.0.5,所以一旦我添加 spring data jpa 作为依赖项,我就会遇到冲突,因为我正在使用 3.1.0。

我试过使用 maven excludes,但没有取得太大的成功。

最佳答案

我成功地将 Spring Data JPA 1.0.3 与 Spring 3.1.0 集成在一起。这是一个看起来不错的剥离 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>example</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>3.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>3.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>3.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>3.1.0.RELEASE</version>
            <scope>test</scope>
        </dependency>

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

</project>

查看传递依赖,一切似乎都正常:

$ mvn dependency:tree
    com.example:example:jar:1.0.0-SNAPSHOT
+- org.springframework:spring-core:jar:3.1.0.RELEASE:compile
|  +- org.springframework:spring-asm:jar:3.1.0.RELEASE:compile
|  \- commons-logging:commons-logging:jar:1.1.1:compile
+- org.springframework:spring-aspects:jar:3.1.0.RELEASE:compile
|  +- org.springframework:spring-beans:jar:3.1.0.RELEASE:compile
|  +- org.springframework:spring-context:jar:3.1.0.RELEASE:compile
|  |  +- org.springframework:spring-aop:jar:3.1.0.RELEASE:compile
|  |  \- org.springframework:spring-expression:jar:3.1.0.RELEASE:compile
|  \- org.springframework:spring-context-support:jar:3.1.0.RELEASE:compile
+- org.springframework:spring-orm:jar:3.1.0.RELEASE:compile
|  +- org.springframework:spring-jdbc:jar:3.1.0.RELEASE:compile
|  \- org.springframework:spring-tx:jar:3.1.0.RELEASE:compile
|     \- aopalliance:aopalliance:jar:1.0:compile
+- org.springframework:spring-test:jar:3.1.0.RELEASE:test (scope not updated to compile)
\- org.springframework.data:spring-data-jpa:jar:1.0.3.RELEASE:compile
   +- org.springframework.data:spring-data-commons-core:jar:1.1.0.RELEASE:compile
   +- org.slf4j:slf4j-api:jar:1.6.1:compile
   +- org.slf4j:jcl-over-slf4j:jar:1.6.1:runtime
   \- org.aspectj:aspectjrt:jar:1.6.8:compile

你有什么样的冲突?

关于java - 在 Spring 3.1.0 中使用 Spring Data JPA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9618336/

相关文章:

java - 如何触发@Timeout注解?

java - 我的单例模式实现错误

spring - "jmsListenerContainerFactory"是 SimpleJmsListenerEndpoint 使用的默认工厂

spring - 使用 PostGIS Geometry Hibernate 持续失败

spring - Quartz 调度程序未启动。在待机模式

java - 提高 BufferedReader 速度

java - spring oauth2自定义登录错误

java - 分别使用 Spring ApplicationContext 和 DispatcherServlet 时,网页无法打开/损坏

java - 当 WAR 通过 Maven 构建/部署到 WildFly 时,静态 init block 中出现 NullPointerException

java - JUnit 测试沙箱没有网络和文件访问权限?