Class RequestMappingHandlerMapping
- All Implemented Interfaces:
- Aware, BeanNameAware, InitializingBean, ApplicationContextAware, EmbeddedValueResolverAware, Ordered, HandlerMapping
RequestMappingInfoHandlerMapping that creates
RequestMappingInfo instances from type-level and method-level
@RequestMapping and @HttpExchange
annotations.- Since:
- 5.0
- Author:
- Rossen Stoyanchev, Sam Brannen, Olga Maciaszek-Sharma, Yongjun Hong
- 
Field SummaryFields inherited from class AbstractHandlerMappingmappingsLoggerFields inherited from class ApplicationObjectSupportloggerFields inherited from interface HandlerMappingAPI_VERSION_ATTRIBUTE, BEST_MATCHING_HANDLER_ATTRIBUTE, BEST_MATCHING_PATTERN_ATTRIBUTE, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTEFields inherited from interface OrderedHIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidDetects handler methods at initialization.protected RequestMappingInfocreateRequestMappingInfo(RequestMapping requestMapping, @Nullable RequestCondition<?> customCondition) Create aRequestMappingInfofrom the supplied@RequestMappingannotation, meta-annotation, or synthesized result of merging annotation attributes within an annotation hierarchy.protected RequestMappingInfocreateRequestMappingInfo(HttpExchange httpExchange, @Nullable RequestCondition<?> customCondition) Create aRequestMappingInfofrom the supplied@HttpExchangeannotation, meta-annotation, or synthesized result of merging annotation attributes within an annotation hierarchy.Return the configuredRequestedContentTypeResolver.protected @Nullable RequestCondition<?> getCustomMethodCondition(Method method) Protected method to provide a custom method-level request condition.protected @Nullable RequestCondition<?> getCustomTypeCondition(Class<?> handlerType) Protected method to provide a custom type-level request condition.protected @Nullable RequestMappingInfogetMappingForMethod(Method method, Class<?> handlerType) Uses type-level and method-level@RequestMappingand@HttpExchangeannotations to create theRequestMappingInfo.The configured path prefixes as a read-only, possibly empty map.protected @Nullable 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.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.voidsetContentTypeResolver(RequestedContentTypeResolver contentTypeResolver) Set theRequestedContentTypeResolverto 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.Methods inherited from class RequestMappingInfoHandlerMappinggetDirectPaths, getHandlerInternal, getMappingComparator, getMatchingMapping, handleMatch, handleNoMatchMethods inherited from class AbstractHandlerMethodMappingcreateHandlerMethod, detectHandlerMethods, getCorsConfiguration, getHandlerMethods, handlerMethodsInitialized, hasCorsConfigurationSource, initHandlerMethods, lookupHandlerMethod, unregisterMappingMethods inherited from class AbstractHandlerMappingformatMappingName, getApiVersionStrategy, getCorsProcessor, getHandler, getOrder, getPathPatternParser, setApiVersionStrategy, setBeanName, setCorsConfigurations, setCorsConfigurationSource, setCorsProcessor, setOrder, setUseCaseSensitiveMatch
- 
Constructor Details- 
RequestMappingHandlerMappingpublic RequestMappingHandlerMapping()
 
- 
- 
Method Details- 
setPathPrefixesConfigure path prefixes to apply to controller methods.Prefixes are used to enrich the mappings of every @RequestMappingmethod and@HttpExchangemethod whose controller type is matched by a correspondingPredicatein the map. The prefix for the first matching predicate is used, assuming the input map has predictable order.Consider using HandlerTypePredicateto group controllers.- Parameters:
- prefixes- a map with path prefixes as key
- Since:
- 5.1
- See Also:
 
- 
getPathPrefixes
- 
setContentTypeResolverSet theRequestedContentTypeResolverto use to determine requested media types. If not set, the default constructor is used.
- 
getContentTypeResolverReturn the configuredRequestedContentTypeResolver.
- 
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>
 
- 
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 type-level and method-level@RequestMappingand@HttpExchangeannotations to create theRequestMappingInfo.For CGLIB proxy classes, additional validation is performed based on method visibility: - Private methods cannot be overridden and therefore cannot be used as handler methods.
- Package-private methods from different packages are inaccessible and must be changed to public or protected.
 - 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, ornullif the method does not have a@RequestMappingor@HttpExchangeannotation
- See Also:
 
- 
getCustomTypeConditionProtected method to provide a custom type-level request condition.The custom RequestConditioncan 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
 
- 
getCustomMethodConditionProtected method to provide a custom method-level request condition.The custom RequestConditioncan 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, meta-annotation, or synthesized result of merging annotation attributes within an annotation hierarchy.
- 
createRequestMappingInfoprotected RequestMappingInfo createRequestMappingInfo(HttpExchange httpExchange, @Nullable RequestCondition<?> customCondition) Create aRequestMappingInfofrom the supplied@HttpExchangeannotation, meta-annotation, or synthesized result of merging annotation attributes within an annotation hierarchy.- Since:
- 6.1
 
- 
resolveEmbeddedValuesInPatterns
- 
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
 
- 
registerHandlerMethodDescription copied from class:AbstractHandlerMethodMappingRegister a handler method and its unique mapping. Invoked at startup for each detected handler method.- 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
 
- 
initCorsConfigurationprotected @Nullable 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>
 
 
-