Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
AAdewunmi opened this issue Nov 7, 2022 · 4 comments
Assignees

Comments

@AAdewunmi
Copy link

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) 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 AAdewunmi changed the title Update Spring Guide: "Building REST services with Spring" Error: The method methodOn(Class) is undefined for the type EmployeeController. Nov 17, 2022
@AAdewunmi
Copy link
Author

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

@AAdewunmi AAdewunmi reopened this Nov 17, 2022
@AAdewunmi
Copy link
Author

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

@hasanpolatt
Copy link

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

@robertmcnees robertmcnees self-assigned this May 15, 2024
@robertmcnees
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants