【问题标题】:Using Spring Data JPA with Spring 3.1.0在 Spring 3.1.0 中使用 Spring Data JPA
【发布时间】:2012-03-25 23:25:21
【问题描述】:

有人知道如何使用 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,但没有取得多大成功。

【问题讨论】:

    标签: java spring maven spring-data-jpa


    【解决方案1】:

    我成功地将 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
    

    你有什么样的冲突?

    【讨论】:

    • 是的,你会得到很多:org.springframework:spring-beans:jar:3.0.5.RELEASE:compile - omitted for conflict with 3.1.0.RELEASE - 这很好,maven 选择了更新的或明确声明的依赖项。功能,而不是错误:-)。您的最终工件将使用更新的版本。
    猜你喜欢
    • 1970-01-01
    • 2016-12-10
    • 2018-08-06
    • 2016-06-22
    • 2017-07-17
    • 1970-01-01
    • 2021-05-05
    • 1970-01-01
    • 2017-05-09
    相关资源
    最近更新 更多