I am following the same tutorial and came across the same problem with the methods "linkTo" and "methodOn".
It seems like the import should be from:
import static org.springframework.hateoas.server.mvc.ControllerLinkBuilder.*;
However, it seems it is already deprecated and there is now WebMvcLinkBuilder suggested to be used:
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;
I found clues in this class:
https://github.com/spring-projects/spring-hateoas-examples/blob/master/simplified/src/main/java/org/springframework/hateoas/examples/EmployeeController.java
More over, at the bottom of the tutorial page there is a link to the GitHub repo of complete project:
https://github.com/spring-guides/tut-rest
I also found problems running the "LoadDatabase.java" when following the tutorial. To fix this, I had to make it implement the CommandLineRunner and put the original code inside it's run method:
@Component
public class LoadDatabase implements CommandLineRunner {
private static final Logger log = LoggerFactory.getLogger(LoadDatabase.class);
@Override
public void run(String... args) throws Exception {
employeeRepository.save(new Employee("Bilbo", "Baggins", "burglar"));
employeeRepository.save(new Employee("Frodo", "Baggins", "thief"));
employeeRepository.findAll().forEach(employee -> log.info("Preloaded " + employee));
orderRepository.save(new Order("MacBook Pro", Status.COMPLETED));
orderRepository.save(new Order("iPhone", Status.IN_PROGRESS));
orderRepository.findAll().forEach(order -> {
log.info("Preloaded " + order);
});
}
@Autowired
EmployeeRepository employeeRepository;
@Autowired
OrderRepository orderRepository;
}