Class RequestMappingHandlerMapping
- java.lang.Object
- org.springframework.context.support.ApplicationObjectSupport
- org.springframework.web.context.support.WebApplicationObjectSupport
- org.springframework.web.servlet.handler.AbstractHandlerMapping
- org.springframework.web.servlet.handler.AbstractHandlerMethodMapping<RequestMappingInfo>
- org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping
- org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping
- All Implemented Interfaces:
Aware,InitializingBean,ApplicationContextAware,EmbeddedValueResolverAware,Ordered,ServletContextAware,MatchableHandlerMapping,HandlerMapping
public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMapping implements MatchableHandlerMapping, EmbeddedValueResolverAware
CreatesRequestMappingInfoinstances from type and method-level@RequestMappingannotations in@Controllerclasses.- Since:
- 3.1
- Author:
- Arjen Poutsma, Rossen Stoyanchev, Sam Brannen
Field Summary
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
Fields inherited from interface org.springframework.web.servlet.HandlerMapping
BEST_MATCHING_HANDLER_ATTRIBUTE, BEST_MATCHING_PATTERN_ATTRIBUTE, INTROSPECT_TYPE_LEVEL_MAPPING, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTE
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor Summary
Constructors Constructor Description RequestMappingHandlerMapping()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()Detects handler methods at initialization.protected RequestMappingInfocreateRequestMappingInfo(RequestMapping requestMapping, RequestCondition<?> customCondition)Create aRequestMappingInfofrom the supplied@RequestMappingannotation, which is either a directly declared annotation, a meta-annotation, or the synthesized result of merging annotation attributes within an annotation hierarchy.ContentNegotiationManagergetContentNegotiationManager()Return the configuredContentNegotiationManager.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()Return the file extensions to use for suffix pattern matching.protected RequestMappingInfogetMappingForMethod(Method method, Class<?> handlerType)Uses method and type-level @RequestMappingannotations to create the RequestMappingInfo.protected CorsConfigurationinitCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo)Extract and return the CORS configuration for the mapping.protected booleanisHandler(Class<?> beanType)Whether the given type is a handler with handler methods.RequestMatchResultmatch(HttpServletRequest request, String pattern)Determine whether the given request matches the request criteria.protected String[]resolveEmbeddedValuesInPatterns(String[] patterns)Resolve placeholder values in the given array of patterns.voidsetContentNegotiationManager(ContentNegotiationManager contentNegotiationManager)Set theContentNegotiationManagerto use to determine requested media types.voidsetEmbeddedValueResolver(StringValueResolver resolver)Set the StringValueResolver to use for resolving embedded definition values.voidsetUseRegisteredSuffixPatternMatch(boolean useRegisteredSuffixPatternMatch)Whether suffix pattern matching should work only against path extensions explicitly registered with theContentNegotiationManager.voidsetUseSuffixPatternMatch(boolean useSuffixPatternMatch)Whether to use suffix pattern match (".*") when matching patterns to requests.voidsetUseTrailingSlashMatch(boolean useTrailingSlashMatch)Whether to match to URLs irrespective of the presence of a trailing slash.booleanuseRegisteredSuffixPatternMatch()Whether to use registered suffixes for pattern matching.booleanuseSuffixPatternMatch()Whether to use suffix pattern matching.booleanuseTrailingSlashMatch()Whether to match to URLs irrespective of the presence of a trailing slash.Methods inherited from class org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping
getMappingComparator, getMappingPathPatterns, getMatchingMapping, handleMatch, handleNoMatch
Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMethodMapping
createHandlerMethod, detectHandlerMethods, getCorsConfiguration, getHandlerInternal, getHandlerMethods, getHandlerMethodsForMappingName, getNamingStrategy, handlerMethodsInitialized, initHandlerMethods, lookupHandlerMethod, registerHandlerMethod, registerMapping, setDetectHandlerMethodsInAncestorContexts, setHandlerMethodMappingNamingStrategy, unregisterMapping
Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMapping
adaptInterceptor, detectMappedInterceptors, extendInterceptors, getAdaptedInterceptors, getCorsConfigurations, getCorsHandlerExecutionChain, getCorsProcessor, getDefaultHandler, getHandler, getHandlerExecutionChain, getMappedInterceptors, getOrder, getPathMatcher, getUrlPathHelper, initApplicationContext, initInterceptors, setAlwaysUseFullPath, setCorsConfigurations, setCorsProcessor, setDefaultHandler, setInterceptors, setOrder, setPathMatcher, setRemoveSemicolonContent, setUrlDecode, setUrlPathHelper
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.web.servlet.HandlerMapping
getHandler
Constructor Detail
RequestMappingHandlerMapping
public RequestMappingHandlerMapping()
Method Detail
setUseSuffixPatternMatch
public void setUseSuffixPatternMatch(boolean useSuffixPatternMatch)
Whether to use suffix pattern match (".*") when matching patterns to requests. If enabled a method mapped to "/users" also matches to "/users.*".The default value is
true.Also see
setUseRegisteredSuffixPatternMatch(boolean)for more fine-grained control over specific suffixes to allow.
setUseRegisteredSuffixPatternMatch
public void setUseRegisteredSuffixPatternMatch(boolean useRegisteredSuffixPatternMatch)
Whether suffix pattern matching should work only against path extensions explicitly registered with theContentNegotiationManager. 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".
setUseTrailingSlashMatch
public void setUseTrailingSlashMatch(boolean useTrailingSlashMatch)
Whether to match to URLs irrespective of the presence of a trailing slash. If enabled a method mapped to "/users" also matches to "/users/".The default value is
true.
setContentNegotiationManager
public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager)
Set theContentNegotiationManagerto use to determine requested media types. If not set, the default constructor is used.
getContentNegotiationManager
public ContentNegotiationManager getContentNegotiationManager()
Return the configuredContentNegotiationManager.
setEmbeddedValueResolver
public void setEmbeddedValueResolver(StringValueResolver resolver)
Description copied from interface:EmbeddedValueResolverAwareSet the StringValueResolver to use for resolving embedded definition values.- Specified by:
setEmbeddedValueResolverin interfaceEmbeddedValueResolverAware
afterPropertiesSet
public void afterPropertiesSet()
Description copied from class:AbstractHandlerMethodMappingDetects handler methods at initialization.- Specified by:
afterPropertiesSetin interfaceInitializingBean- Overrides:
afterPropertiesSetin classAbstractHandlerMethodMapping<RequestMappingInfo>
useSuffixPatternMatch
public boolean useSuffixPatternMatch()
Whether to use suffix pattern matching.
useRegisteredSuffixPatternMatch
public boolean useRegisteredSuffixPatternMatch()
Whether to use registered suffixes for pattern matching.
useTrailingSlashMatch
public boolean useTrailingSlashMatch()
Whether to match to URLs irrespective of the presence of a trailing slash.
getFileExtensions
public List<String> getFileExtensions()
Return the file extensions to use for suffix pattern matching.
isHandler
protected boolean isHandler(Class<?> beanType)
Whether the given type is a handler with handler methods.Expects a handler to have either a type-level @
Controllerannotation or a type-level @RequestMappingannotation.- Specified by:
isHandlerin classAbstractHandlerMethodMapping<RequestMappingInfo>- Parameters:
beanType- the type of the bean being checked- Returns:
- "true" if this a handler type, "false" otherwise.
getMappingForMethod
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType)
Uses method and type-level @RequestMappingannotations to create the RequestMappingInfo.- Specified by:
getMappingForMethodin classAbstractHandlerMethodMapping<RequestMappingInfo>- Parameters:
method- the method to provide a mapping forhandlerType- the handler type, possibly a sub-type of the method's declaring class- Returns:
- the created RequestMappingInfo, or
nullif the method does not have a@RequestMappingannotation. - See Also:
getCustomMethodCondition(Method),getCustomTypeCondition(Class)
getCustomTypeCondition
protected RequestCondition<?> getCustomTypeCondition(Class<?> handlerType)
Provide a custom type-level request condition. The customRequestConditioncan 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
AbstractRequestConditionfor custom condition types and usingCompositeRequestConditionto provide multiple custom conditions.- Parameters:
handlerType- the handler type for which to create the condition- Returns:
- the condition, or
null
getCustomMethodCondition
protected RequestCondition<?> getCustomMethodCondition(Method method)
Provide a custom method-level request condition. The customRequestConditioncan 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
AbstractRequestConditionfor custom condition types and usingCompositeRequestConditionto provide multiple custom conditions.- Parameters:
method- the handler method for which to create the condition- Returns:
- the condition, or
null
createRequestMappingInfo
protected RequestMappingInfo createRequestMappingInfo(RequestMapping requestMapping, RequestCondition<?> customCondition)
Create aRequestMappingInfofrom the supplied@RequestMappingannotation, which is either a directly declared annotation, a meta-annotation, or the synthesized result of merging annotation attributes within an annotation hierarchy.
resolveEmbeddedValuesInPatterns
protected String[] resolveEmbeddedValuesInPatterns(String[] patterns)
Resolve placeholder values in the given array of patterns.- Returns:
- a new array with updated patterns
match
public RequestMatchResult match(HttpServletRequest request, String pattern)
Description copied from interface:MatchableHandlerMappingDetermine whether the given request matches the request criteria.- Specified by:
matchin interfaceMatchableHandlerMapping- Parameters:
request- the current requestpattern- the pattern to match- Returns:
- the result from request matching, or
nullif none
initCorsConfiguration
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo)
Description copied from class:AbstractHandlerMethodMappingExtract and return the CORS configuration for the mapping.- Overrides:
initCorsConfigurationin classAbstractHandlerMethodMapping<RequestMappingInfo>