Class RequestMappingHandlerMapping
- All Implemented Interfaces:
Aware, BeanNameAware, InitializingBean, ApplicationContextAware, EmbeddedValueResolverAware, Ordered, ServletContextAware, MatchableHandlerMapping, HandlerMapping
RequestMappingInfo instances from type-level and method-level
@RequestMapping and @HttpExchange
annotations in @Controller classes.- Since:
- 3.1
- Author:
- Arjen Poutsma, Rossen Stoyanchev, Sam Brannen, Olga Maciaszek-Sharma, Yongjun Hong
-
Field Summary
Fields inherited from class AbstractHandlerMapping
mappingsLoggerFields inherited from class ApplicationObjectSupport
loggerFields inherited from interface HandlerMapping
API_VERSION_ATTRIBUTE, BEST_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 Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier 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.Obtain aRequestMappingInfo.BuilderConfigurationthat reflects the internal configuration of thisHandlerMappingand can be used to setRequestMappingInfo.Builder.options(RequestMappingInfo.BuilderConfiguration).Return the configuredContentNegotiationManager.protected @Nullable RequestCondition<?> getCustomMethodCondition(Method method) Provide a custom method-level request condition.protected @Nullable RequestCondition<?> getCustomTypeCondition(Class<?> handlerType) 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.Deprecated, for removal: This API element is subject to removal in a future version.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.Methods inherited from class RequestMappingInfoHandlerMapping
getDirectPaths, getHandlerInternal, getMappingComparator, getMatchingMapping, handleMatch, handleNoMatchMethods inherited from class AbstractHandlerMethodMapping
createHandlerMethod, detectHandlerMethods, getCandidateBeanNames, getCorsConfiguration, getHandlerMethods, getHandlerMethodsForMappingName, getNamingStrategy, handlerMethodsInitialized, hasCorsConfigurationSource, initHandlerMethods, lookupHandlerMethod, processCandidateBean, setDetectHandlerMethodsInAncestorContexts, setHandlerMethodMappingNamingStrategy, setPatternParser, unregisterMappingMethods inherited from class AbstractHandlerMapping
adaptInterceptor, detectMappedInterceptors, extendInterceptors, formatMappingName, getAdaptedInterceptors, getApiVersionStrategy, getCorsConfigurationSource, getCorsHandlerExecutionChain, getCorsProcessor, getDefaultHandler, getHandler, getHandlerExecutionChain, getMappedInterceptors, getOrder, getPathMatcher, getPatternParser, getUrlPathHelper, initApplicationContext, initInterceptors, initLookupPath, setAlwaysUseFullPath, setApiVersionStrategy, setBeanName, setCorsConfigurations, setCorsConfigurationSource, setCorsProcessor, setDefaultHandler, setInterceptors, setOrder, setPathMatcher, setRemoveSemicolonContent, setUrlDecode, setUrlPathHelper, usesPathPatternsMethods inherited from class WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextMethods inherited from class ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, obtainApplicationContext, requiredContextClass, setApplicationContextMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface HandlerMapping
getHandler, usesPathPatternsMethods inherited from interface MatchableHandlerMapping
getPatternParser
-
Constructor Details
-
RequestMappingHandlerMapping
public RequestMappingHandlerMapping()
-
-
Method Details
-
setPathPrefixes
Configure 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
-
getPathPrefixes
-
setContentNegotiationManager
Set theContentNegotiationManagerto use to determine requested media types. If not set, the default constructor is used. -
getContentNegotiationManager
Return the configuredContentNegotiationManager. -
setEmbeddedValueResolver
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>- See Also:
-
getBuilderConfiguration
Obtain aRequestMappingInfo.BuilderConfigurationthat 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
-
isHandler
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
Uses 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 classAbstractHandlerMethodMapping<RequestMappingInfo>- Parameters:
method- the method to provide a mapping forhandlerType- 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:
-
getCustomTypeCondition
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
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, meta-annotation, or synthesized result of merging annotation attributes within an annotation hierarchy. -
createRequestMappingInfo
protected 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
-
registerMapping
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
Register 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 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
-
match
@Deprecated(since="7.0", forRemoval=true) public @Nullable RequestMatchResult match(jakarta.servlet.http.HttpServletRequest request, String pattern) Deprecated, for removal: This API element is subject to removal in a future version.Description 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 interfaceMatchableHandlerMapping- Parameters:
request- the current requestpattern- the pattern to match- Returns:
- the result from request matching, or
nullif none
-
initCorsConfiguration
protected @Nullable 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>
-