Inherit value for @RequestMapping if not overridden [SPR-11421] #16048
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: declined
A suggestion or change that we don't feel we should currently apply
type: enhancement
A general enhancement
Christopher Smith opened SPR-11421 and commented
If a
@RequestMapping
path is defined on a superclass, the path is inherited by subclasses (e.g., the@RequestMapping
s on their methods are relative to the superclass's base path).I'm using the Spring content negotiation feature to serve both HTML views and a JSON API from the same URLs, based on the client's
Accept
header. In order to overload the URL, I have to differentiate the implementation methods by having differentproduces
attributes; I specify "application/json
" in the@RequestMapping
for the JSON subclass.The
value
attribute on@RequestMapping
is not required, but if a subclass is annotated, Spring overrides the path from the parent with an empty string and attaches the subclass's controllers to the root path.In order to avoid having to duplicate
@RequestMapping
data on each class, I suggest changing the resolver to treat a missingvalue
attribute in a@RequestMapping
as if the annotation were not there, rather than implicitly treating it as an empty string. The behavior of a@RequestMapping
on a subclass without avalue
attribute is not specified by the docs, so this wouldn't break the existing contract. In the alternative, I suggest makingvalue
a required attribute to eliminate this pitfall.Affects: 4.0.1
Attachments:
The text was updated successfully, but these errors were encountered: