RequestMappingHandlerMapping
@Deprecated public class DefaultAnnotationHandlerMapping extends AbstractDetectingUrlHandlerMapping
HandlerMapping
interface that maps handlers based on HTTP paths expressed through the
RequestMapping
annotation at the type or method level.
Registered by default in DispatcherServlet
on Java 5+. NOTE: If you define custom HandlerMapping beans in your
DispatcherServlet context, you need to add a DefaultAnnotationHandlerMapping bean
explicitly, since custom HandlerMapping beans replace the default mapping strategies.
Defining a DefaultAnnotationHandlerMapping also allows for registering custom
interceptors:
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> <property name="interceptors"> ... </property> </bean>Annotated controllers are usually marked with the
Controller
stereotype
at the type level. This is not strictly necessary when RequestMapping
is
applied at the type level (since such a handler usually implements the
Controller
interface). However,
Controller
is required for detecting RequestMapping
annotations
at the method level if RequestMapping
is not present at the type level.
NOTE: Method-level mappings are only allowed to narrow the mapping expressed at the class level (if any). HTTP paths need to uniquely map onto specific handler beans, with any given HTTP path only allowed to be mapped onto one specific handler bean (not spread across multiple handler beans). It is strongly recommended to co-locate related handler methods into the same bean.
The AnnotationMethodHandlerAdapter
is responsible for processing
annotated handler methods, as mapped by this HandlerMapping. For
RequestMapping
at the type level, specific HandlerAdapters such as
SimpleControllerHandlerAdapter
apply.
RequestMapping
,
AnnotationMethodHandlerAdapter
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.Class<?>,RequestMapping> |
cachedMappings
Deprecated.
|
(package private) static java.lang.String |
USE_DEFAULT_SUFFIX_PATTERN
Deprecated.
|
private boolean |
useDefaultSuffixPattern
Deprecated.
|
logger
BEST_MATCHING_PATTERN_ATTRIBUTE, INTROSPECT_TYPE_LEVEL_MAPPING, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTE
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
DefaultAnnotationHandlerMapping()
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addUrlsForPath(java.util.Set<java.lang.String> urls,
java.lang.String path)
Deprecated.
Add URLs and/or URL patterns for the given path.
|
protected java.lang.String[] |
determineUrlsForHandler(java.lang.String beanName)
Deprecated.
Checks for presence of the
RequestMapping
annotation on the handler class and on any of its methods. |
protected java.lang.String[] |
determineUrlsForHandlerMethods(java.lang.Class<?> handlerType)
Deprecated.
Derive URL mappings from the handler's method-level mappings.
|
protected java.lang.String[] |
determineUrlsForHandlerMethods(java.lang.Class<?> handlerType,
boolean hasTypeLevelMapping)
Deprecated.
Derive URL mappings from the handler's method-level mappings.
|
void |
setUseDefaultSuffixPattern(boolean useDefaultSuffixPattern)
Deprecated.
Set whether to register paths using the default suffix pattern as well:
i.e.
|
protected boolean |
supportsTypeLevelMappings()
Deprecated.
Indicates whether this handler mapping support type-level mappings.
|
protected void |
validateHandler(java.lang.Object handler,
HttpServletRequest request)
Deprecated.
Validate the given annotated handler against the current request.
|
protected void |
validateMapping(RequestMapping mapping,
HttpServletRequest request)
Deprecated.
Validate the given type-level mapping metadata against the current request,
checking HTTP request method and parameter conditions.
|
detectHandlers, initApplicationContext, setDetectHandlersInAncestorContexts
buildPathExposingHandler, exposePathWithinMapping, exposeUriTemplateVariables, getHandlerInternal, getHandlerMap, getRootHandler, lookupHandler, registerHandler, registerHandler, setLazyInitHandlers, setRootHandler
adaptInterceptor, detectMappedInterceptors, extendInterceptors, getAdaptedInterceptors, getDefaultHandler, getHandler, getHandlerExecutionChain, getMappedInterceptors, getOrder, getPathMatcher, getUrlPathHelper, initInterceptors, setAlwaysUseFullPath, setDefaultHandler, setInterceptors, setOrder, setPathMatcher, setRemoveSemicolonContent, setUrlDecode, setUrlPathHelper
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
static final java.lang.String USE_DEFAULT_SUFFIX_PATTERN
private boolean useDefaultSuffixPattern
private final java.util.Map<java.lang.Class<?>,RequestMapping> cachedMappings
public DefaultAnnotationHandlerMapping()
public void setUseDefaultSuffixPattern(boolean useDefaultSuffixPattern)
Default is "true". Turn this convention off if you intend to interpret
your @RequestMapping
paths strictly.
Note that paths which include a ".xxx" suffix or end with "/" already will not be transformed using the default suffix pattern in any case.
protected java.lang.String[] determineUrlsForHandler(java.lang.String beanName)
RequestMapping
annotation on the handler class and on any of its methods.determineUrlsForHandler
in class AbstractDetectingUrlHandlerMapping
beanName
- the name of the candidate beannull
or an empty array if noneprotected java.lang.String[] determineUrlsForHandlerMethods(java.lang.Class<?> handlerType, boolean hasTypeLevelMapping)
handlerType
- the handler type to introspecthasTypeLevelMapping
- whether the method-level mappings are nested
within a type-level mappingprotected java.lang.String[] determineUrlsForHandlerMethods(java.lang.Class<?> handlerType)
handlerType
- the handler type to introspectprotected void addUrlsForPath(java.util.Set<java.lang.String> urls, java.lang.String path)
urls
- the Set of URLs for the current beanpath
- the currently introspected pathprotected void validateHandler(java.lang.Object handler, HttpServletRequest request) throws java.lang.Exception
validateHandler
in class AbstractUrlHandlerMapping
handler
- the handler object to validaterequest
- current HTTP requestjava.lang.Exception
- if validation failedvalidateMapping(org.springframework.web.bind.annotation.RequestMapping, HttpServletRequest)
protected void validateMapping(RequestMapping mapping, HttpServletRequest request) throws java.lang.Exception
mapping
- the mapping metadata to validaterequest
- current HTTP requestjava.lang.Exception
- if validation failedprotected boolean supportsTypeLevelMappings()
AbstractUrlHandlerMapping
false
.supportsTypeLevelMappings
in class AbstractUrlHandlerMapping