java - 将 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 !在此处输入图像描述
请帮忙
解决方案
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
推荐阅读
- java - Java GET HTTP openConnection() 未正确编码 JSON 输出字符串
- amazon-cognito - 如何仅使用 auth 包配置 Amplify?
- sql - 如何将返回值从一个 PostgreSQL 查询传递到另一个?
- openwhisk - 什么是 OpenWhisk“集合”?
- python - 在字典值中解包元组
- azure-sql - 运行引用凭据的 Add-AzSqlElasticJobStep 错误
- python-3.x - 字符串列表到整数列表中
- android-jetpack-compose - Jetpack Compose - 滚动到列中的重点可组合
- ffmpeg - 将一堆 .pkl 文件合并为一个,然后转换为 .fbx(在 Windows 上)
- java - 区间中的随机数,边界接近最大和最小整数值