我无法导入任何HATEOAS元素,尽管它在我的build.gradle中似乎是正确实现的:
implementation 'org.springframework.boot:spring-boot-starter-hateoas'这是我的进口品:
import org.springframework.hateoas.Resource;
import org.springframework.hateoas.Resources;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;以下是一些错误:
$ ./gradlew build
> Task :compileJava FAILED
path\src\main\java\payroll\EmployeeController.java:5: error: cannot find symbol
import org.springframework.hateoas.Resource;
^
symbol: class Resource
location: package org.springframework.hateoas
path\src\main\java\payroll\EmployeeController.java:6: error: cannot find symbol
import org.springframework.hateoas.Resources;
^
symbol: class Resources
location: package org.springframework.hateoas
path\src\main\java\payroll\EmployeeController.java:15: error: package org.springframework.hateoas.mvc does not exist
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.*;
^
path\src\main\java\payroll\EmployeeController.java:41: error: cannot find symbol
Resource<Employee> one(@PathVariable Long id) {
^
symbol: class Resource
location: class EmployeeController
4 errors我不认为这是相关的,但我正在使用IntelliJ,并试图完成本教程:https://spring.io/guides/tutorials/bookmarks/
当我搜索这个问题时,我找不到任何解决方案,我也不知道问题出在哪里,所以我不知道还能尝试什么。
发布于 2020-03-09 07:14:08
经过更多的研究,我意识到spring.io教程已经过时了。在玩了一会儿之后,IntelliJ开始显示org.springframework.hateoas,但是教程提供的导入仍然不起作用。
我最终找到了指向源代码的链接,代码已经更新,而教程没有。
https://github.com/spring-guides/tut-rest/tree/master/rest/src/main/java/payroll
基本上,资源已被EntityModel取代,资源被CollectionModel所取代,导入的结构也发生了变化。
在更新代码以匹配源代码之后,当我向员工发送GET请求时,我得到了预期的响应:
{"id":1,"name":"Bilbo Baggins","role":"burglar","_links":{"self":{"href":"http://localhost:8080/employees/1"},"employees":{"href":"http://localhost:8080/employees"}}}发布于 2021-11-07 12:39:39
你可能发现了一个过时的教程。现在,您需要将应用程序代码迁移到较新版本的HATEOAS。
https://stackoverflow.com/questions/60567900
复制相似问题