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

nhu*_*uvy 6 spring hibernate maven spring-boot

我使用Spring启动创建一个框架应用程序.这是我的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>
Run Code Online (Sandbox Code Playgroud)

我坚持这一步:

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

在此输入图像描述

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

覆盖hibernate-core的托管版本4.3.11.Final

在此输入图像描述

帮我解决这些问题.

And*_*son 16

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

使用Hibernate 5的更安全的方法是覆盖Boot的依赖关系管理.当您使用spring-boot-starter-parentpom的父母时,您可以通过覆盖该hibernate.version属性来实现:

<properties>
    <hibernate.version>5.1.0.Final</hibernate.version>
</properties>
Run Code Online (Sandbox Code Playgroud)

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

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

  • 有关如何使用Gradle执行此操作的任何建议? (3认同)

The*_*ect 6

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

Eclipse只是提醒它.如果您确实要更改该依赖项的版本,则可以忽略该警告.

更新:

请参阅Andy的回答:https://stackoverflow.com/a/35385268/1433665