Details
-
Type:
Improvement
-
Status: Resolved
-
Priority:
Minor
-
Resolution: Won't Fix
-
Affects Version/s: 4.0.1
-
Fix Version/s: None
-
Component/s: Web
-
Labels:
-
Last commented by a User:true
Description
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 different produces 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 missing value 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 a value attribute is not specified by the docs, so this wouldn't break the existing contract. In the alternative, I suggest making value a required attribute to eliminate this pitfall.