Class RequestMappingHandlerMapping
- All Implemented Interfaces:
- Aware,- BeanNameAware,- InitializingBean,- ApplicationContextAware,- EmbeddedValueResolverAware,- Ordered,- ServletContextAware,- MatchableHandlerMapping,- HandlerMapping
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
 #24179.- Since:
- 3.1
- Author:
- Arjen Poutsma, Rossen Stoyanchev, Sam Brannen
- 
Field SummaryFields inherited from class org.springframework.web.servlet.handler.AbstractHandlerMappingmappingsLoggerFields inherited from class org.springframework.context.support.ApplicationObjectSupportloggerFields inherited from interface org.springframework.web.servlet.HandlerMappingBEST_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_ATTRIBUTEFields inherited from interface org.springframework.core.OrderedHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidDetects 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.Obtain aRequestMappingInfo.BuilderConfigurationthat can reflects the internal configuration of thisHandlerMappingand can be used to setRequestMappingInfo.Builder.options(RequestMappingInfo.BuilderConfiguration).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.Deprecated.as of 5.2.4.protected RequestMappingInfogetMappingForMethod(Method method, Class<?> handlerType) Uses method and type-level @RequestMappingannotations to create the RequestMappingInfo.The configured path prefixes as a read-only, possibly empty map.protected CorsConfigurationinitCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) Extract and return the CORS configuration for the mapping.protected booleanWhether the given type is a handler with handler methods.match(HttpServletRequest request, String pattern) Determine whether the request matches the given pattern.protected voidregisterHandlerMethod(Object handler, Method method, RequestMappingInfo mapping) Register a handler method and its unique mapping.voidregisterMapping(RequestMappingInfo mapping, Object handler, Method method) Register the given mapping.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.voidsetPathPrefixes(Map<String, Predicate<Class<?>>> prefixes) Configure path prefixes to apply to controller methods.voidsetPatternParser(PathPatternParser patternParser) Set thePathPatternParserto parsepatternswith for URL path matching.voidsetUseRegisteredSuffixPatternMatch(boolean useRegisteredSuffixPatternMatch) Deprecated.as of 5.2.4.voidsetUseSuffixPatternMatch(boolean useSuffixPatternMatch) Deprecated.as of 5.2.4.voidsetUseTrailingSlashMatch(boolean useTrailingSlashMatch) Deprecated.as of 6.0, seePathPatternParser.setMatchOptionalTrailingSeparator(boolean)booleanDeprecated.as of 5.2.4.booleanDeprecated.as of 5.2.4.booleanWhether to match to URLs irrespective of the presence of a trailing slash.Methods inherited from class org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMappinggetDirectPaths, getHandlerInternal, getMappingComparator, getMappingPathPatterns, getMatchingMapping, handleMatch, handleNoMatchMethods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMethodMappingcreateHandlerMethod, detectHandlerMethods, getCandidateBeanNames, getCorsConfiguration, getHandlerMethods, getHandlerMethodsForMappingName, getNamingStrategy, handlerMethodsInitialized, hasCorsConfigurationSource, initHandlerMethods, lookupHandlerMethod, processCandidateBean, setDetectHandlerMethodsInAncestorContexts, setHandlerMethodMappingNamingStrategy, unregisterMappingMethods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMappingadaptInterceptor, 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, usesPathPatternsMethods inherited from class org.springframework.web.context.support.WebApplicationObjectSupportgetServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextMethods inherited from class org.springframework.context.support.ApplicationObjectSupportgetApplicationContext, getMessageSourceAccessor, obtainApplicationContext, requiredContextClass, setApplicationContextMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.web.servlet.HandlerMappinggetHandler, usesPathPatternsMethods inherited from interface org.springframework.web.servlet.handler.MatchableHandlerMappinggetPatternParser
- 
Constructor Details- 
RequestMappingHandlerMappingpublic RequestMappingHandlerMapping()
 
- 
- 
Method Details- 
setPatternParserDescription copied from class:AbstractHandlerMappingSet thePathPatternParserto parsepatternswith for URL path matching. Parsed patterns provide a more modern and efficient alternative to String path matching viaAntPathMatcher.Note: This property is mutually exclusive with the below properties, all of which are not necessary for parsed patterns and are ignored when a PathPatternParseris available:- AbstractHandlerMapping.setAlwaysUseFullPath(boolean)-- parsed patterns always use the full path and consider the servletPath only when a Servlet is mapped by path prefix.
- AbstractHandlerMapping.setRemoveSemicolonContent(boolean)-- parsed patterns always ignore semicolon content for path matching purposes, but path parameters remain available for use in controllers via- @MatrixVariable.
- AbstractHandlerMapping.setUrlDecode(boolean)-- parsed patterns match one decoded path segment at a time and therefore don't need to decode the full path.
- AbstractHandlerMapping.setUrlPathHelper(org.springframework.web.util.UrlPathHelper)-- for parsed patterns, the request path is parsed once in- DispatcherServletor in- ServletRequestPathFilterusing- ServletRequestPathUtilsand cached in a request attribute.
- AbstractHandlerMapping.setPathMatcher(org.springframework.util.PathMatcher)-- a parsed patterns encapsulates the logic for path matching and does need a- PathMatcher.
 By default, as of 6.0, this is set to a PathPatternParserinstance with default settings and therefore use of parsed patterns is enabled. Set this tonullto switch to String path matching viaAntPathMatcherinstead.- Overrides:
- setPatternParserin class- AbstractHandlerMethodMapping<RequestMappingInfo>
- Parameters:
- patternParser- the parser to use
 
- 
setUseSuffixPatternMatchDeprecated.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 tofalse. In 5.3 the default changes tofalseand use of this property becomes unnecessary.Whether to use suffix pattern match (".*") when matching patterns to requests. If enabled a method mapped to "/users" also matches to "/users.*".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 setPatternParser(PathPatternParser)is configured.
- 
setUseRegisteredSuffixPatternMatchDeprecated.as of 5.2.4. See class level note on the deprecation of path extension config options.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". Note: This property is ignored when setPatternParser(PathPatternParser)is configured.
- 
setUseTrailingSlashMatchDeprecated.as of 6.0, seePathPatternParser.setMatchOptionalTrailingSeparator(boolean)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 was changed in 6.0 from truetofalsein order to support the deprecation of the property.
- 
setPathPrefixesConfigure path prefixes to apply to controller methods.Prefixes are used to enrich the mappings of every @RequestMappingmethod whose controller type is matched by the correspondingPredicate. The prefix for the first matching predicate is used.Consider using HandlerTypePredicateto group controllers.- Parameters:
- prefixes- a map with path prefixes as key
- Since:
- 5.1
 
- 
getPathPrefixesThe configured path prefixes as a read-only, possibly empty map.- Since:
- 5.1
 
- 
setContentNegotiationManagerSet theContentNegotiationManagerto use to determine requested media types. If not set, the default constructor is used.
- 
getContentNegotiationManagerReturn the configuredContentNegotiationManager.
- 
setEmbeddedValueResolverDescription copied from interface:EmbeddedValueResolverAwareSet the StringValueResolver to use for resolving embedded definition values.- Specified by:
- setEmbeddedValueResolverin interface- EmbeddedValueResolverAware
 
- 
afterPropertiesSetpublic void afterPropertiesSet()Description copied from class:AbstractHandlerMethodMappingDetects handler methods at initialization.- Specified by:
- afterPropertiesSetin interface- InitializingBean
- Overrides:
- afterPropertiesSetin class- AbstractHandlerMethodMapping<RequestMappingInfo>
- See Also:
 
- 
useSuffixPatternMatchDeprecated.as of 5.2.4. See deprecation notice onsetUseSuffixPatternMatch(boolean).Whether to use registered suffixes for pattern matching.
- 
useRegisteredSuffixPatternMatchDeprecated.as of 5.2.4. See deprecation notice onsetUseRegisteredSuffixPatternMatch(boolean).Whether to use registered suffixes for pattern matching.
- 
useTrailingSlashMatchpublic boolean useTrailingSlashMatch()Whether to match to URLs irrespective of the presence of a trailing slash.
- 
getFileExtensionsDeprecated.as of 5.2.4. See class-level note on the deprecation of path extension config options.Return the file extensions to use for suffix pattern matching.
- 
getBuilderConfigurationObtain aRequestMappingInfo.BuilderConfigurationthat can reflects the internal configuration of thisHandlerMappingand can be used to setRequestMappingInfo.Builder.options(RequestMappingInfo.BuilderConfiguration).This is useful for programmatic registration of request mappings via registerHandlerMethod(Object, Method, RequestMappingInfo).- Returns:
- the builder configuration that reflects the internal state
- Since:
- 5.3.14
 
- 
isHandlerWhether the given type is a handler with handler methods.Expects a handler to have a type-level @ Controllerannotation.- Specified by:
- isHandlerin class- AbstractHandlerMethodMapping<RequestMappingInfo>
- Parameters:
- beanType- the type of the bean being checked
- Returns:
- "true" if this a handler type, "false" otherwise.
 
- 
getMappingForMethodUses method and type-level @RequestMappingannotations to create the RequestMappingInfo.- Specified by:
- getMappingForMethodin class- AbstractHandlerMethodMapping<RequestMappingInfo>
- Parameters:
- method- the method to provide a mapping for
- handlerType- the handler type, possibly a subtype of the method's declaring class
- Returns:
- the created RequestMappingInfo, or nullif the method does not have a@RequestMappingannotation.
- See Also:
 
- 
getCustomTypeConditionProvide 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
 
- 
getCustomMethodConditionProvide 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
 
- 
createRequestMappingInfoprotected RequestMappingInfo createRequestMappingInfo(RequestMapping requestMapping, @Nullable 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.
- 
resolveEmbeddedValuesInPatternsResolve placeholder values in the given array of patterns.- Returns:
- a new array with updated patterns
 
- 
registerMappingDescription copied from class:AbstractHandlerMethodMappingRegister the given mapping.This method may be invoked at runtime after initialization has completed. - Overrides:
- registerMappingin class- AbstractHandlerMethodMapping<RequestMappingInfo>
- Parameters:
- mapping- the mapping for the handler method
- handler- the handler
- method- the method
 
- 
registerHandlerMethodRegister a handler method and its unique mapping. Invoked at startup for each detected handler method.Note: To create the RequestMappingInfo, please usegetBuilderConfiguration()and set the options onRequestMappingInfo.Builder.options(RequestMappingInfo.BuilderConfiguration)to match how thisHandlerMappingis configured. This is important for example to ensure use ofPathPatternorPathMatcherbased matching.- Overrides:
- registerHandlerMethodin class- AbstractHandlerMethodMapping<RequestMappingInfo>
- Parameters:
- handler- the bean name of the handler or the handler instance
- method- the method to register
- mapping- the mapping conditions associated with the handler method
 
- 
matchDescription copied from interface:MatchableHandlerMappingDetermine whether the request matches the given pattern. Use this method whenMatchableHandlerMapping.getPatternParser()returnsnullwhich means that theHandlerMappingis using String pattern matching.- Specified by:
- matchin interface- MatchableHandlerMapping
- Parameters:
- request- the current request
- pattern- the pattern to match
- Returns:
- the result from request matching, or nullif none
 
- 
initCorsConfigurationprotected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) Description copied from class:AbstractHandlerMethodMappingExtract and return the CORS configuration for the mapping.- Overrides:
- initCorsConfigurationin class- AbstractHandlerMethodMapping<RequestMappingInfo>
 
 
-