Class RequestMappingHandlerMapping
- java.lang.Object
- org.springframework.context.support.ApplicationObjectSupport
- org.springframework.web.reactive.handler.AbstractHandlerMapping
- org.springframework.web.reactive.result.method.AbstractHandlerMethodMapping<RequestMappingInfo>
- org.springframework.web.reactive.result.method.RequestMappingInfoHandlerMapping
- org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping
- All Implemented Interfaces:
Aware,BeanNameAware,InitializingBean,ApplicationContextAware,EmbeddedValueResolverAware,Ordered,HandlerMapping
public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMapping implements EmbeddedValueResolverAware
An extension ofRequestMappingInfoHandlerMappingthat createsRequestMappingInfoinstances from class-level and method-level@RequestMappingannotations.- Since:
- 5.0
- Author:
- Rossen Stoyanchev, Sam Brannen
Field Summary
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
Fields inherited from interface org.springframework.web.reactive.HandlerMapping
BEST_MATCHING_HANDLER_ATTRIBUTE, BEST_MATCHING_PATTERN_ATTRIBUTE, 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.RequestedContentTypeResolvergetContentTypeResolver()Return the configuredRequestedContentTypeResolver.protected RequestCondition<?>getCustomMethodCondition(Method method)Provide a custom method-level request condition.protected RequestCondition<?>getCustomTypeCondition(Class<?> handlerType)Provide a custom type-level request condition.protected RequestMappingInfogetMappingForMethod(Method method, Class<?> handlerType)Uses method and type-level @RequestMappingannotations to create the RequestMappingInfo.Map<String,Predicate<Class<?>>>getPathPrefixes()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 booleanisHandler(Class<?> beanType)Whether 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 org.springframework.web.reactive.result.method.RequestMappingInfoHandlerMapping
getHandlerInternal, getMappingComparator, getMatchingMapping, handleMatch, handleNoMatch
Methods inherited from class org.springframework.web.reactive.result.method.AbstractHandlerMethodMapping
createHandlerMethod, detectHandlerMethods, getCorsConfiguration, getHandlerMethods, handlerMethodsInitialized, hasCorsConfigurationSource, initHandlerMethods, lookupHandlerMethod, unregisterMapping
Methods inherited from class org.springframework.web.reactive.handler.AbstractHandlerMapping
formatMappingName, getCorsProcessor, getHandler, getOrder, getPathPatternParser, setBeanName, setCorsConfigurations, setCorsConfigurationSource, setCorsProcessor, setOrder, setUseCaseSensitiveMatch, setUseTrailingSlashMatch
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, initApplicationContext, isContextRequired, obtainApplicationContext, requiredContextClass, setApplicationContext
Constructor Detail
RequestMappingHandlerMapping
public RequestMappingHandlerMapping()
Method Detail
setPathPrefixes
public void setPathPrefixes(Map<String,Predicate<Class<?>>> prefixes)
Configure path prefixes to apply to controller methods.Prefixes are used to enrich the mappings of every
@RequestMappingmethod 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:
HandlerTypePredicate
getPathPrefixes
public Map<String,Predicate<Class<?>>> getPathPrefixes()
The configured path prefixes as a read-only, possibly empty map.- Since:
- 5.1
setContentTypeResolver
public void setContentTypeResolver(RequestedContentTypeResolver contentTypeResolver)
Set theRequestedContentTypeResolverto use to determine requested media types. If not set, the default constructor is used.
getContentTypeResolver
public RequestedContentTypeResolver getContentTypeResolver()
Return the configuredRequestedContentTypeResolver.
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>
isHandler
protected boolean isHandler(Class<?> beanType)
Whether the given type is a handler with handler methods. Expects a handler to have a type-level @Controllerannotation.- Specified by:
isHandlerin classAbstractHandlerMethodMapping<RequestMappingInfo>- Parameters:
beanType- the type of the bean being checked- Returns:
- "true" if this a handler type, "false" otherwise.
getMappingForMethod
@Nullable 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
@Nullable 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
@Nullable 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, @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.
resolveEmbeddedValuesInPatterns
protected String[] resolveEmbeddedValuesInPatterns(String[] patterns)
Resolve placeholder values in the given array of patterns.- Returns:
- a new array with updated patterns
registerMapping
public void registerMapping(RequestMappingInfo mapping, Object handler, Method method)
Description copied from class:AbstractHandlerMethodMappingRegister the given mapping.This method may be invoked at runtime after initialization has completed.
- Overrides:
registerMappingin classAbstractHandlerMethodMapping<RequestMappingInfo>- Parameters:
mapping- the mapping for the handler methodhandler- the handlermethod- the method
registerHandlerMethod
protected void registerHandlerMethod(Object handler, Method method, RequestMappingInfo mapping)
Description copied from class:AbstractHandlerMethodMappingRegister a handler method and its unique mapping. Invoked at startup for each detected handler method.- Overrides:
registerHandlerMethodin classAbstractHandlerMethodMapping<RequestMappingInfo>- Parameters:
handler- the bean name of the handler or the handler instancemethod- the method to registermapping- the mapping conditions associated with the handler method
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>