Skip to content

Bug in Documentation: @RepositoryRestController is NOT exposed under base-path [DATAREST-1327] #1686

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

Closed
spring-projects-issues opened this issue Dec 25, 2018 · 2 comments
Assignees
Labels
status: duplicate A duplicate of another issue type: bug A general bug

Comments

@spring-projects-issues
Copy link

Doogiemuc opened DATAREST-1327 and commented

The spring-data-rest doc sais:

Controllers annotated with @RepositoryRestController are served from the API base path defined in RepositoryRestConfiguration.setBasePath, which is used by all other RESTful endpoints (for example, /api).

https://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.overriding-sdr-response-handlers

This is not true.

@RepositoryRestController
public class MyCustomController {
  @RequestMapping(value = "/myCustomResource")
  public ResponseEntity<?> customResource() { ... }
}

is not mapped at all.

One MUST use a @RequestMapping on class level.  Even @RequestMapping("/")  works to map MyCustomController. See also https://stackoverflow.com/questions/38607421/spring-data-rest-controllers-behaviour-and-usage-of-basepathawarecontroller

There is a workaround:

@RepositoryRestController
@RequestMapping("${spring.data.rest.base-path}")
public class MyCustomController { ... }

At least update the documentation to describe this correctly


Reference URL: https://stackoverflow.com/questions/38607421/spring-data-rest-controllers-behaviour-and-usage-of-basepathawarecontroller

1 votes, 4 watchers

@spring-projects-issues
Copy link
Author

jntesteves commented

I converted a system to SDR and didn't take notice of this part of documentation, so my properties don't include spring.data.rest.base-path=/api, but it still includes the old line server.servlet.contextPath=/api and that seems to be honored by SDR. I only have a @RepositoryRestController annotation on my controllers and they do override SDR's methods under /api.

But using, for example @RequestMapping("/users") in my UserController class seems to break SDR's endpoints for this entity in this setup, so I had to repeat @RequestMapping("/users") with this endpoint's base URI in every method. Not ideal. I'll want to fix my controllers when we reach a conclusion on this issue

@spring-projects-issues spring-projects-issues added the type: bug A general bug label Dec 31, 2020
odrotbohm added a commit that referenced this issue Oct 6, 2021
…stMapping.

When we detected @BasePathAwareController and @RepositoryRestController instances, we now reject types that use @RequestMapping on the class level as doing so causes an inevitable registration of the controller with Spring MVC.

Fixes #1342, #1628, #1686, #1946.
odrotbohm added a commit that referenced this issue Oct 6, 2021
…stMapping.

When we detected @BasePathAwareController and @RepositoryRestController instances, we now reject types that use @RequestMapping on the class level as doing so causes an inevitable registration of the controller with Spring MVC.

Fixes #1342, #1628, #1686, #1946.
odrotbohm added a commit that referenced this issue Oct 6, 2021
…stMapping.

When we detected @BasePathAwareController and @RepositoryRestController instances, we now reject types that use @RequestMapping on the class level as doing so causes an inevitable registration of the controller with Spring MVC.

Fixes #1342, #1628, #1686, #1946.
@odrotbohm
Copy link
Member

Duplicates #1342. See the my latest comment over there.

@odrotbohm odrotbohm added the status: duplicate A duplicate of another issue label Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants