tut-rest icon indicating copy to clipboard operation
tut-rest copied to clipboard

Error: The method methodOn(Class) is undefined for the type EmployeeController.

Open AAdewunmi opened this issue 2 years ago • 3 comments

Hi,

I would like to suggest an udate to section: "What makes something RESTful?"

Users of the guide are not intuitively aware that the import: "import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;" will fix the error: The method methodOn(Class<EmployeeController>) is undefined for the type EmployeeController.

The WebMvcLinkBuilder import could be placed directly within the code snippet and a link to Spring HATEOAS - Reference Documentation placed below the code.

import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.*;

@GetMapping("/employees/{id}")
EntityModel<Employee> one(@PathVariable Long id) {

  Employee employee = repository.findById(id) //
      .orElseThrow(() -> new EmployeeNotFoundException(id));

  return EntityModel.of(employee, //
      linkTo(methodOn(EmployeeController.class).one(id)).withSelfRel(),
      linkTo(methodOn(EmployeeController.class).all()).withRel("employees"));
}

Spring HATEOAS - Reference Documentation

I don't mind being assigned this issue.

😎

AAdewunmi avatar Nov 07 '22 13:11 AAdewunmi

I've submiited a Pull request for this issue. Guess it's time to close it 😎

AAdewunmi avatar Nov 17 '22 15:11 AAdewunmi

Thought I'd keep this issue open incase someone encounters this error ...

AAdewunmi avatar Nov 17 '22 15:11 AAdewunmi

Yes, I encountered this error. Looks like they fixed the code but the guide still seems to be incomplete.

hasanpolatt avatar Apr 03 '23 00:04 hasanpolatt

Hi @AAdewunmi. Thank you for the issue. This particular bit of code was causing some confusion and spawned a few different issues in the tracker. I pushed a PR #127 that should address this issue, specifically with this line.

Please try again and let us know if things can still be improved. For now I will close the issue as I believe #127 should have cleared things up. Thanks again for raising this.

robertmcnees avatar May 15 '24 14:05 robertmcnees