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

Class-Level Request Mapping on Controller and Custom POST Breaks GETs [DATAREST-1265] #1628

Closed
spring-projects-issues opened this issue Jul 25, 2018 · 3 comments
Assignees
Labels
status: duplicate A duplicate of another issue type: documentation A documentation update type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

Mike Whittemore opened DATAREST-1265 and commented

If I have a UserRepository and then create a custom controller endpoint for handling resource creation, e.g.

@RepositoryRestController
@RequestMapping("/users")
class UserController {
    ...
    @PostMapping
    public ResponseEntity<?> create(...) {...}
}

requests like GET /users stop working with the response:

{{ "timestamp": "2018-07-25T01:45:15.780+0000", "status": 405, "error": "Method Not Allowed", "message": "Request method 'GET' not supported", "path": "/users"}

If I move the request mapping from the class to the method (and if there are multiple endpoints/paths, to every one) everything works as expected:

@RepositoryRestController
class UserController {
    ...
    @PostMapping("/users")
    public ResponseEntity<?> create(...) {...}
} 

This seems like a bug to me, since it is inconsistent with WebMVC behavior and I only discovered the "fix" via "voodoo" programming


No further details from DATAREST-1265

@spring-projects-issues
Copy link
Author

Oliver Drotbohm commented

That's an unfortunate side effect of Spring MVC insisting to handle controllers with a class level @RequestMapping in it's default HandlerMapping implementation. Spring Data REST uses a custom one and has to rely on users not using a class-level @RequestMapping. I'll turn this ticket into a documentation one, so that this gets more obvious. /cc rstoyanchev

@spring-projects-issues
Copy link
Author

Rossen Stoyanchev commented

The main case is interface-based proxies as far as I know. The interface would have the @RequestMapping but not the @Controller annotation, so we would miss it otherwise. juergen.hoeller, perhaps we can refine this, and use @RequestMapping alone, i.e. without @Conntroller, only if it is coming from an interface?

@spring-projects-issues spring-projects-issues added type: documentation A documentation update type: enhancement A general enhancement labels 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 odrotbohm added the status: duplicate A duplicate of another issue label Oct 7, 2021
@odrotbohm
Copy link
Member

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

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: documentation A documentation update type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants