Description
When @RequestBody(required = false)
is declared on a controller interface method, Spring currently ignores this annotation during request mapping. As a result, mappings incorrectly require a request body even when required = false is set on the interface.
This leads to incorrect matching behavior, especially when the implementation method does not override the @RequestBody annotation.
Expected behavior:
Spring should detect the @RequestBody annotation on interface methods and respect the required flag during request mapping, allowing requests without bodies when required = false
.
Actual behavior:
Only the annotations on the implementation method are considered, causing required = false on interfaces to be ignored.
Steps to reproduce:
- Define a controller interface method annotated with @RequestBody(required = false)
- Implement the interface without overriding the annotation
- Register the handler and observe that Spring expects a body even if required = false
- Make a request with no body and no Content-Type and observe that the request fails
Suggested fix:
Use AnnotatedMethod
to retrieve parameter annotations from both implementation and interface methods to correctly determine the required flag.
Additional context:
I have a patch that fixes this and adds tests to cover both interface and implementation overrides.