Issue
I can't import any HATEOAS elements, although it seems to be correctly implemented in my build.gradle:
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
And here are my imports:
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.*;
And here are the errors:
$ ./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
I don't think it's relevant, but I am using IntelliJ and am trying to work through this tutorial: https://spring.io/guides/tutorials/bookmarks/
I couldn't find any solutions when I googled the issue, and I don't really understand what the problem is, so I don't know what else to try.
Solution
Having researched a bit more, I realized that the spring.io tutorial is outdated. After playing around a little, IntelliJ started showing org.springframework.hateoas, but the imports provided by the tutorial still didn't work.
I eventually found the link to the source code, and the code has been updated, while the tutorial has not.
https://github.com/spring-guides/tut-rest/tree/master/rest/src/main/java/payroll
Basically, Resource has been replaced with EntityModel, Resources has been replaced with CollectionModel, and the structure of the imports has changed.
After updating my code to match the source code, I got the expected response when I sent a GET request for an Employee:
{"id":1,"name":"Bilbo Baggins","role":"burglar","_links":{"self":{"href":"http://localhost:8080/employees/1"},"employees":{"href":"http://localhost:8080/employees"}}}
Answered By - Jeffrey Maier