首页 > 解决方案 > 将 Spring HATEOAS 添加到 pom.xml 失败

问题描述

所以我正在关注关于使用 spring boot 构建 Restful 服务的教程,我必须将 HATEOAS 依赖项添加到 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.2.4.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.project</groupId>
	<artifactId>Project</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>Project</name>
	<description>Demo project for Spring Boot library management system</description>

	<properties>
		<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-web</artifactId>
		</dependency>

		<dependency>
			<groupId>com.h2database</groupId>
			<artifactId>h2</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-hateoas</artifactId>
		</dependency>
	</dependencies>

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

</project>

这就是我得到的错误

在此处输入图像描述

而我的目标是使用无法导入的 Resource <> from import org.springframework.hateoas.Resource !在此处输入图像描述

请帮忙

标签: javaspringhateoas

解决方案


Resource在 Spring Hateoas 1.0中已重命名为EntityModel,所以您正在寻找org.springframework.hateoas.EntityModel

来源:https ://docs.spring.io/spring-hateoas/docs/current/reference/html/#migrate-to-1.0.changes.representation-models :

ResourceSupport/Resource/Resources/PagedResources 组的类从来没有真正感觉命名合适。毕竟,这些类型实际上并不体现资源,而是可以通过超媒体信息和可供性丰富的表示模型。以下是新名称与旧名称的映射方式:

ResourceSupport 现在是 RepresentationModel

资源现在是 EntityModel

Resources 现在是 CollectionModel

PagedResources 现在是 PagedModel


推荐阅读