Skip to content

Doc: Overriding of default values for HandlerMapping, HandlerAdapter et al. in DispatcherServlet is not obvious [SPR-4086] #8765

@spring-projects-issues

Description

@spring-projects-issues

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:

  1. Users need to be made aware of the implications of overriding the defaults
  2. Overriding the defaults breaks forward compatibility (see below)
  3. 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:

  1. Addition of a HandlerMapping (and/or HandlerAdapter) while keeping the existing defaults
  2. Removal of a HandlerMapping (and/or HandlerAdapter); it is less clear that this is a valid or common case on its own
  3. 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:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions