我使用 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-dependency:1.3.2.RELEASE
当我尝试手动添加 Hibernate 5.1.0.Final 时,出现此通知:
覆盖 hibernate-core 的托管版本 4.3.11.Final
帮我解决这些问题。
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 开始的。因此,您可能会遇到一些不兼容的问题。如果你不想成为right在最前沿,5.0.x 可能是一个更安全的选择。它将成为 Spring Boot 1.4 中默认的 Hibernate 版本。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)