-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Chris Lee opened SPR-4086 and commented
DispatcherServlet chooses reasonable defaults for HandlerMapping, HandlerAdapter (and others). For these two specific types, there are multiple defaults listed:
org.springframework.web.servlet.HandlerMapping=org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,
org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping
org.springframework.web.servlet.HandlerAdapter=org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,
org.springframework.web.servlet.mvc.throwaway.ThrowawayControllerHandlerAdapter,
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
While the JavaDoc for DispatcherServlet does state that any user-added beans of these types override the defaults, there are several challenges with this approach:
- Users need to be made aware of the implications of overriding the defaults
- Overriding the defaults breaks forward compatibility (see below)
- It seems excessive / verbose to re-register defaults to get back core functionality
As an example, an existing Spring 2.0.x application that defined its own HandlerMapping(s) would not be able to use the Spring 2.5.x @RequestMapping
functionality without adding DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter beans to their context (after spending time to determine that these were the necessary steps).
There are several use cases to address:
- Addition of a HandlerMapping (and/or HandlerAdapter) while keeping the existing defaults
- Removal of a HandlerMapping (and/or HandlerAdapter); it is less clear that this is a valid or common case on its own
- The combination of 1 & 2, where you want to specify precisely what should be there (remove all defaults and supply your own)
Affects: 2.5 RC2
Issue Links:
- @Controller annotated controllers can not co-exist with not annotated ones. [SPR-4088] #8767
@Controller
annotated controllers can not co-exist with not annotated ones.