I am using Spring Boot 2.2.0.M1 with HATEOAS and Gradle.
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
Right now, Resource
is not found by the IDE (IntelliJ IDEA 2018.3) and ControllerLinkBuilder
is marked as deprecated.
package com.example.restfulwebservicegradle.user;
import static org.springframework.hateoas.server.mvc.ControllerLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
import com.example.restfulwebservicegradle.User;
import com.example.restfulwebservicegradle.UserDaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.server.mvc.ControllerLinkBuilder;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import javax.validation.Valid;
import java.net.URI;
import java.util.List;
@RestController
public class UserResource {
@Autowired
private UserDaoService service;
@GetMapping("users/{id}")
public Resource<User> retrieveUser(@PathVariable int id) {
User user = service.findOne(id);
if (user == null)
throw new UserNotFoundException("id-" + id);
// Resource not found
Resource<User> resource = new Resource<User>(user);
// Deprecated
ControllerLinkBuilder linkTo = linkTo(methodOn(this.getClass()).retrieveAllUsers());
resource.add(linkTo.withRel("all-users"));
return resource;
}
}
The imports available according to the IDE are:
How can I solve this?
My goal is to found Resource
from HATEOAS and to use the substitute of ControllerLinkBuilder
.