2016-02-13 52 views
4

我使用Spring引导创建了一个框架应用程序。这是我pom.xmlSpring Boot:受管版本是1.3.2.RELEASE该工件在org.springframework.boot中进行管理:spring-boot-dependencies:1.3.2.RELEASE

<?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> 

我停留在这一步:

春季启动:托管版本是1.3.2.RELEASE神器 在 org.springframework.boot管理:弹簧启动依存关系:1.3.2.RELEASE

enter image description here

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

压倒一切的托管版本4.3.11.Final对Hibernate核心

enter image description here

帮我解决这些问题。

回答

8

春季启动提供了依赖管理的休眠。警告是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> 

这将确保在其春季启动提供依赖管理所有休眠模块将具有所需的版本。

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

+3

有关如何使用Gradle完成此任务的任何建议? – Snekse

4

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

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

更新:

见刘德华的回答是:https://stackoverflow.com/a/35385268/1433665

+1

按照你的答案并提交链接,最新版本的'休眠-core'是5.1.0.Final ,Spring Boot中的默认版本是4.3.11.Final。 Spring Boot有这个缺点吗? –

+1

这是Spring Boot的特色和巨大卖点。你得到了良好的测试和稳定的依赖关系矩阵,但是你并不总是在这个矩阵中出现边缘问题。如果你想使用更新的依赖关系,你可以覆盖默认的Spring Boot版本。 – luboskrnac

+1

@dovy在Spring引导中有一个github问题来支持Hibernate 5. https://github.com/spring-projects/spring-boot/issues/2763 – TheKojuEffect

0

我有同样的问题,我通过将HIBERNATE的版本更改为4.3.5.Final来解决它。在pom。XML

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

或只需添加hibernate.version到其他属性,如:

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

    <hibernate.version>4.3.5.Final</hibernate.version> 
</properties> 
相关问题