Affects: Spring Web 5.3
If a @RequestMapping annotation is used on a package (in package-info.java), then every controller that is in that package will have a root path given in that annotation.
This could be useful in monolithic projects, that have multiple controllers under similar paths. In this case, the root path of these controllers doesn't have to be spelled out separately for every controller class, but only in their respective packages.
Comment From: poutsma
This feature has been suggested before, but unfortunately introduces ambiguity. Quoting from this comment by @rstoyanchev:
Sounds alright as an idea but there can be ambiguity in other arrangements. For example
@RequestMapping
methods inherited from a base class, or even@RequestMapping
methods from an interface implemented by the controller. Would we look at the package of the class or its super types which could be in a different package. In the case of interfaces, with a JDK proxy in front of the controller class, Spring MVC doesn't even know what the actual controller type is (it's behind a proxy) so it would have to check the package of the interface and furthermore, theoretically at least it could be more than one interface.
Issues #19231 and #20883 discuss alternatives to package-level request mappings.