RequestMappingHandlerMapping.isHandler(…) not only picks up types annotated with @Controller but also ones that are annotated with @RequestMapping on the type level. This is problematic in cases in which other HandlerMapping instances are registered that might be supposed to handle those controllers.

A prominent example of this is Spring Data REST, which registers a dedicated mapping to expose HTTP resources for Spring Data repositories. Users can selectively override those resources by declaring a controller themselves and just declare a handler method for e.g. the URI of an item resource and an HTTP verb of choice. If that controller now declares an @RequestMapping on the type level, the Spring MVC registered one will pick up that class, and not see any other mappings defined for the same URI pattern but exposing support for other HTTP methods potentially available in subsequent HanderMapping implementations.

This is a pretty common error scenario reported by users (see this StackOverflow question for example). It's also pretty hard to explain to users as it involves talking about quite a few implementation details.

Removing the explicit handling of @RequestMapping on the type level bears the risk that controller implementations not also being annotated with @Controller would not be picked up automatically anymore. I haven't found any Spring MVC related documentation that actually shows an example of code not using the annotations in combination when used at the type level. A fix for that issue would be to also annotate the affected controller type with @Controller. I can see this being suboptimal for a release in a minor version but for 6.0 we should at least reevaluate.

Comment From: rstoyanchev

This is a duplicate of #22154. Can you please add the comment there?