public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMapping implements MatchableHandlerMapping, EmbeddedValueResolverAware
RequestMappingInfo instances from type and method-level
@RequestMapping annotations in
@Controller classes.
Deprecation Note:
In 5.2.4,useSuffixPatternMatch and
useRegisteredSuffixPatternMatch
were deprecated in order to discourage use of path extensions for request
mapping and for content negotiation (with similar deprecations in
ContentNegotiationManagerFactoryBean). For further context, please read issue
#24719.loggerBEST_MATCHING_HANDLER_ATTRIBUTE, BEST_MATCHING_PATTERN_ATTRIBUTE, INTROSPECT_TYPE_LEVEL_MAPPING, LOOKUP_PATH, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTEHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE| Constructor and Description |
|---|
RequestMappingHandlerMapping() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet()
Detects handler methods at initialization.
|
protected RequestMappingInfo |
createRequestMappingInfo(RequestMapping requestMapping,
RequestCondition<?> customCondition)
Create a
RequestMappingInfo from the supplied
@RequestMapping annotation, which is either
a directly declared annotation, a meta-annotation, or the synthesized
result of merging annotation attributes within an annotation hierarchy. |
ContentNegotiationManager |
getContentNegotiationManager()
Return the configured
ContentNegotiationManager. |
protected RequestCondition<?> |
getCustomMethodCondition(Method method)
Provide a custom method-level request condition.
|
protected RequestCondition<?> |
getCustomTypeCondition(Class<?> handlerType)
Provide a custom type-level request condition.
|
List<String> |
getFileExtensions()
Deprecated.
as of 5.2.4. See class-level note on the deprecation of path
extension config options.
|
protected RequestMappingInfo |
getMappingForMethod(Method method,
Class<?> handlerType)
Uses method and type-level @
RequestMapping annotations to create
the RequestMappingInfo. |
Map<String,Predicate<Class<?>>> |
getPathPrefixes()
The configured path prefixes as a read-only, possibly empty map.
|
protected CorsConfiguration |
initCorsConfiguration(Object handler,
Method method,
RequestMappingInfo mappingInfo)
Extract and return the CORS configuration for the mapping.
|
protected boolean |
isHandler(Class<?> beanType)
Whether the given type is a handler with handler methods.
|
RequestMatchResult |
match(HttpServletRequest request,
String pattern)
Determine whether the request matches the given pattern.
|
protected void |
registerHandlerMethod(Object handler,
Method method,
RequestMappingInfo mapping)
Register a handler method and its unique mapping.
|
void |
registerMapping(RequestMappingInfo mapping,
Object handler,
Method method)
Register the given mapping.
|
protected String[] |
resolveEmbeddedValuesInPatterns(String[] patterns)
Resolve placeholder values in the given array of patterns.
|
void |
setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager)
Set the
ContentNegotiationManager to use to determine requested media types. |
void |
setEmbeddedValueResolver(StringValueResolver resolver)
Set the StringValueResolver to use for resolving embedded definition values.
|
void |
setPathPrefixes(Map<String,Predicate<Class<?>>> prefixes)
Configure path prefixes to apply to controller methods.
|
void |
setUseRegisteredSuffixPatternMatch(boolean useRegisteredSuffixPatternMatch)
Deprecated.
as of 5.2.4. See class level note on the deprecation of
path extension config options.
|
void |
setUseSuffixPatternMatch(boolean useSuffixPatternMatch)
Deprecated.
as of 5.2.4. See class level note on the deprecation of
path extension config options. As there is no replacement for this method,
in 5.2.x it is necessary to set it to
false. In 5.3 the default
changes to false and use of this property becomes unnecessary. |
void |
setUseTrailingSlashMatch(boolean useTrailingSlashMatch)
Whether to match to URLs irrespective of the presence of a trailing slash.
|
boolean |
useRegisteredSuffixPatternMatch()
Deprecated.
as of 5.2.4. See deprecation notice on
setUseRegisteredSuffixPatternMatch(boolean). |
boolean |
useSuffixPatternMatch()
Deprecated.
as of 5.2.4. See deprecation notice on
setUseSuffixPatternMatch(boolean). |
boolean |
useTrailingSlashMatch()
Whether to match to URLs irrespective of the presence of a trailing slash.
|
getDirectPaths, getHandlerInternal, getMappingComparator, getMappingPathPatterns, getMatchingMapping, handleMatch, handleNoMatchcreateHandlerMethod, detectHandlerMethods, getCandidateBeanNames, getCorsConfiguration, getHandlerMethods, getHandlerMethodsForMappingName, getNamingStrategy, handlerMethodsInitialized, hasCorsConfigurationSource, initHandlerMethods, lookupHandlerMethod, processCandidateBean, setDetectHandlerMethodsInAncestorContexts, setHandlerMethodMappingNamingStrategy, setPatternParser, unregisterMappingadaptInterceptor, detectMappedInterceptors, extendInterceptors, formatMappingName, getAdaptedInterceptors, getCorsConfigurationSource, getCorsHandlerExecutionChain, getCorsProcessor, getDefaultHandler, getHandler, getHandlerExecutionChain, getMappedInterceptors, getOrder, getPathMatcher, getPatternParser, getUrlPathHelper, initApplicationContext, initInterceptors, initLookupPath, setAlwaysUseFullPath, setBeanName, setCorsConfigurations, setCorsConfigurationSource, setCorsProcessor, setDefaultHandler, setInterceptors, setOrder, setPathMatcher, setRemoveSemicolonContent, setUrlDecode, setUrlPathHelper, usesPathPatternsgetServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextgetApplicationContext, getMessageSourceAccessor, obtainApplicationContext, requiredContextClass, setApplicationContextclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetPatternParsergetHandler, usesPathPatterns@Deprecated public void setUseSuffixPatternMatch(boolean useSuffixPatternMatch)
false. In 5.3 the default
changes to false and use of this property becomes unnecessary.By default value this is set to false.
Also see setUseRegisteredSuffixPatternMatch(boolean) for
more fine-grained control over specific suffixes to allow.
Note: This property is ignored when
AbstractHandlerMethodMapping.setPatternParser(PathPatternParser) is configured.
@Deprecated public void setUseRegisteredSuffixPatternMatch(boolean useRegisteredSuffixPatternMatch)
ContentNegotiationManager. This
is generally recommended to reduce ambiguity and to avoid issues such as
when a "." appears in the path for other reasons.
By default this is set to "false".
Note: This property is ignored when
AbstractHandlerMethodMapping.setPatternParser(PathPatternParser) is configured.
public void setUseTrailingSlashMatch(boolean useTrailingSlashMatch)
The default value is true.
public void setPathPrefixes(Map<String,Predicate<Class<?>>> prefixes)
Prefixes are used to enrich the mappings of every @RequestMapping
method whose controller type is matched by the corresponding
Predicate. The prefix for the first matching predicate is used.
Consider using HandlerTypePredicate to group controllers.
prefixes - a map with path prefixes as keypublic Map<String,Predicate<Class<?>>> getPathPrefixes()
public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager)
ContentNegotiationManager to use to determine requested media types.
If not set, the default constructor is used.public ContentNegotiationManager getContentNegotiationManager()
ContentNegotiationManager.public void setEmbeddedValueResolver(StringValueResolver resolver)
EmbeddedValueResolverAwaresetEmbeddedValueResolver in interface EmbeddedValueResolverAwarepublic void afterPropertiesSet()
AbstractHandlerMethodMappingafterPropertiesSet in interface InitializingBeanafterPropertiesSet in class AbstractHandlerMethodMapping<RequestMappingInfo>AbstractHandlerMethodMapping.initHandlerMethods()@Deprecated public boolean useSuffixPatternMatch()
setUseSuffixPatternMatch(boolean).@Deprecated public boolean useRegisteredSuffixPatternMatch()
setUseRegisteredSuffixPatternMatch(boolean).public boolean useTrailingSlashMatch()
@Nullable @Deprecated public List<String> getFileExtensions()
protected boolean isHandler(Class<?> beanType)
Expects a handler to have either a type-level @Controller
annotation or a type-level @RequestMapping annotation.
isHandler in class AbstractHandlerMethodMapping<RequestMappingInfo>beanType - the type of the bean being checked@Nullable protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType)
RequestMapping annotations to create
the RequestMappingInfo.getMappingForMethod in class AbstractHandlerMethodMapping<RequestMappingInfo>method - the method to provide a mapping forhandlerType - the handler type, possibly a sub-type of the method's
declaring classnull if the method
does not have a @RequestMapping annotation.getCustomMethodCondition(Method),
getCustomTypeCondition(Class)@Nullable protected RequestCondition<?> getCustomTypeCondition(Class<?> handlerType)
RequestCondition can be of any type so long as the
same condition type is returned from all calls to this method in order
to ensure custom request conditions can be combined and compared.
Consider extending AbstractRequestCondition for custom
condition types and using CompositeRequestCondition to provide
multiple custom conditions.
handlerType - the handler type for which to create the conditionnull@Nullable protected RequestCondition<?> getCustomMethodCondition(Method method)
RequestCondition can be of any type so long as the
same condition type is returned from all calls to this method in order
to ensure custom request conditions can be combined and compared.
Consider extending AbstractRequestCondition for custom
condition types and using CompositeRequestCondition to provide
multiple custom conditions.
method - the handler method for which to create the conditionnullprotected RequestMappingInfo createRequestMappingInfo(RequestMapping requestMapping, @Nullable RequestCondition<?> customCondition)
RequestMappingInfo from the supplied
@RequestMapping annotation, which is either
a directly declared annotation, a meta-annotation, or the synthesized
result of merging annotation attributes within an annotation hierarchy.protected String[] resolveEmbeddedValuesInPatterns(String[] patterns)
public void registerMapping(RequestMappingInfo mapping, Object handler, Method method)
AbstractHandlerMethodMappingThis method may be invoked at runtime after initialization has completed.
registerMapping in class AbstractHandlerMethodMapping<RequestMappingInfo>mapping - the mapping for the handler methodhandler - the handlermethod - the methodprotected void registerHandlerMethod(Object handler, Method method, RequestMappingInfo mapping)
AbstractHandlerMethodMappingregisterHandlerMethod in class AbstractHandlerMethodMapping<RequestMappingInfo>handler - the bean name of the handler or the handler instancemethod - the method to registermapping - the mapping conditions associated with the handler methodpublic RequestMatchResult match(HttpServletRequest request, String pattern)
MatchableHandlerMappingMatchableHandlerMapping.getPatternParser() returns null which means that the
HandlerMapping is uses String pattern matching.match in interface MatchableHandlerMappingrequest - the current requestpattern - the pattern to matchnull if noneprotected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo)
AbstractHandlerMethodMappinginitCorsConfiguration in class AbstractHandlerMethodMapping<RequestMappingInfo>