【问题标题】:Spring Boot: The managed version is 1.3.2.RELEASE The artifact is managed in org.springframework.boot:spring-boot-dependencies:1.3.2.RELEASESpring Boot:管理的版本是 1.3.2.RELEASE 工件在 org.springframework.boot:spring-boot-dependencies:1.3.2.RELEASE 中管理
【发布时间】:2016-05-24 16:16:25
【问题描述】:

我使用 Spring boot 创建了一个框架应用程序。这是我的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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.lynas</groupId>
    <artifactId>SpringMVCHibernate</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>SpringMVCHibernate</name>
    <description>SpringMVCHibernate</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.2.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

我卡在这一步了:

Spring Boot:托管版本是 1.3.2.RELEASE 工件是 管理在 org.springframework.boot:spring-boot-dependencies:1.3.2.RELEASE

当我尝试手动添加 Hiberante 5.1.0.Final 时,出现此通知:

覆盖托管版本 4.3.11.Final 用于休眠核心

帮我解决这些问题。

【问题讨论】:

    标签: spring hibernate maven spring-boot


    【解决方案1】:

    Spring Boot 为 Hibernate 提供依赖管理。警告是 Eclipse 告诉您,您已通过直接在依赖项上声明版本来覆盖此依赖项管理。这是一件冒险的事情,因为您最终可能会在类路径上混合使用 Hibernate 版本。事实上,看看你的 pom,你已经覆盖了 hibernate-core 的版本,但没有覆盖 hibernate-entitymanager 的版本。这意味着您将在类路径上拥有前者的 5.1.0.Final 和后者的 4.3.11.Final。这几乎肯定会导致运行时出现问题。

    使用 Hibernate 5 的更安全的方法是覆盖 Boot 的依赖管理。当您使用 spring-boot-starter-parent 作为 pom 的父级时,您可以通过覆盖 hibernate.version 属性来做到这一点:

    <properties>
        <hibernate.version>5.1.0.Final</hibernate.version>
    </properties>
    

    这将确保 Spring Boot 为其提供依赖管理的所有 Hibernate 模块都将具有所需的版本。

    最后,请注意。 Hibernate 5.1 是非常新的版本,并且包含一些重大更改,甚至从 5.0.x 开始。因此,您可能会遇到一些不兼容的问题。如果您不想正确处于最前沿,5.0.x 可能是更安全的选择。它将成为 Spring Boot 1.4 中默认的 Hibernate 版本。

    【讨论】:

    • 对如何使用 Gradle 执行此操作有任何建议吗?
    • 我想知道在哪里可以找到列表以找到可以覆盖为&lt;hibernate.version&gt; 的属性名称?一定有一个我还找不到的地方的列表。
    • spring-boot-dependencies pom 中定义了spring-boot-starter-parent 的父级。您的 IDE 应该允许您导航到 pom 以查看其内容。如果做不到这一点,你可以在 GitHub 上找到源代码。这里是 2.1.5 版本,例如:github.com/spring-projects/spring-boot/blob/…
    • 如何在 intellij ide 中得到类似的警告,我最近开始使用
    【解决方案2】:

    Spring Boot 自动定义本附录中列出的依赖项的版本。 http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#appendix-dependency-versions

    Eclipse 只是在提醒它。 如果你真的想改变那个依赖的版本,你可以忽略这个警告。

    更新:

    查看安迪的回答:https://stackoverflow.com/a/35385268/1433665

    【讨论】:

    • 按照你的答案和参考链接,hibernate-core 的最新版本是 5.1.0.Final,Spring Boot 中的默认版本是 4.3.11.Final。这是 Spring Boot 的缺点吗?
    • 这是 Spring Boot 的特点和巨大卖点。你得到了经过良好测试和稳定的依赖矩阵,但你并不总是在这个矩阵中得到最前沿的东西。如果你想使用更新的依赖,你可以覆盖默认的 Spring Boot 版本。
    • @dovy Spring boot 中存在一个 github 问题以支持 Hibernate 5。github.com/spring-projects/spring-boot/issues/2763
    • 警告不应被忽略。使用当前配置,类路径上将混合使用 Hibernate 版本
    • @AndyWilkinson 感谢您告诉我。您的回答解决了我在生成的战争中遇到多个休眠 jar 的问题。谢谢!
    【解决方案3】:

    除了上面的答案。我的问题是 STS/Eclipse 的旧版本。使用最新最好的 Spring Tools 重新安装后,错误已解决。 https://spring.io/tools

    【讨论】:

      猜你喜欢
      • 2016-06-15
      • 2016-06-03
      • 2020-07-11
      • 1970-01-01
      • 1970-01-01
      • 2014-09-27
      • 1970-01-01
      • 2019-02-07
      • 2016-04-17
      相关资源
      最近更新 更多