public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMapping implements EmbeddedValueResolverAware
RequestMappingInfoHandlerMapping
that creates
RequestMappingInfo
instances from class-level and method-level
@RequestMapping
annotations.Modifier and Type | Field and Description |
---|---|
private RequestMappingInfo.BuilderConfiguration |
config |
private RequestedContentTypeResolver |
contentTypeResolver |
private StringValueResolver |
embeddedValueResolver |
private boolean |
useRegisteredSuffixPatternMatch |
private boolean |
useSuffixPatternMatch |
private boolean |
useTrailingSlashMatch |
logger
BEST_MATCHING_PATTERN_ATTRIBUTE, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTE
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
RequestMappingHandlerMapping() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Detects handler methods at initialization.
|
private RequestMappingInfo |
createRequestMappingInfo(java.lang.reflect.AnnotatedElement element)
Delegates to
createRequestMappingInfo(RequestMapping, RequestCondition) ,
supplying the appropriate custom RequestCondition depending on whether
the supplied annotatedElement is a class or method. |
protected RequestMappingInfo |
createRequestMappingInfo(RequestMapping requestMapping,
RequestCondition<?> customCondition)
Create a
RequestMappingInfo from the supplied
@RequestMapping annotation, which is either
a directly declared annotation, a meta-annotation, or the synthesized
result of merging annotation attributes within an annotation hierarchy. |
RequestedContentTypeResolver |
getContentTypeResolver()
Return the configured
RequestedContentTypeResolver . |
protected RequestCondition<?> |
getCustomMethodCondition(java.lang.reflect.Method method)
Provide a custom method-level request condition.
|
protected RequestCondition<?> |
getCustomTypeCondition(java.lang.Class<?> handlerType)
Provide a custom type-level request condition.
|
java.util.Set<java.lang.String> |
getFileExtensions()
Return the file extensions to use for suffix pattern matching.
|
protected RequestMappingInfo |
getMappingForMethod(java.lang.reflect.Method method,
java.lang.Class<?> handlerType)
Uses method and type-level @
RequestMapping annotations to create
the RequestMappingInfo. |
protected CorsConfiguration |
initCorsConfiguration(java.lang.Object handler,
java.lang.reflect.Method method,
RequestMappingInfo mappingInfo)
Extract and return the CORS configuration for the mapping.
|
protected boolean |
isHandler(java.lang.Class<?> beanType)
Whether the given type is a handler with handler methods.
|
private java.lang.String |
resolveCorsAnnotationValue(java.lang.String value) |
protected java.lang.String[] |
resolveEmbeddedValuesInPatterns(java.lang.String[] patterns)
Resolve placeholder values in the given array of patterns.
|
void |
setContentTypeResolver(RequestedContentTypeResolver contentTypeResolver)
Set the
RequestedContentTypeResolver to use to determine requested media types. |
void |
setEmbeddedValueResolver(StringValueResolver resolver)
Set the StringValueResolver to use for resolving embedded definition values.
|
void |
setUseRegisteredSuffixPatternMatch(boolean useRegisteredSuffixPatternMatch)
Whether suffix pattern matching should work only against path extensions
explicitly registered with the configured
RequestedContentTypeResolver . |
void |
setUseSuffixPatternMatch(boolean useSuffixPatternMatch)
Whether to use suffix pattern matching.
|
void |
setUseTrailingSlashMatch(boolean useTrailingSlashMatch)
Whether to match to URLs irrespective of the presence of a trailing slash.
|
private void |
updateCorsConfig(CorsConfiguration config,
CrossOrigin annotation) |
boolean |
useRegisteredSuffixPatternMatch()
Whether to use registered suffixes for pattern matching.
|
boolean |
useSuffixPatternMatch()
Whether to use suffix pattern matching.
|
boolean |
useTrailingSlashMatch()
Whether to match to URLs irrespective of the presence of a trailing slash.
|
getMappingComparator, getMappingPathPatterns, getMatchingMapping, handleMatch, handleNoMatch
createHandlerMethod, detectHandlerMethods, getCorsConfiguration, getHandlerInternal, getHandlerMethods, handlerMethodsInitialized, initHandlerMethods, lookupHandlerMethod, registerHandlerMethod, registerMapping, unregisterMapping
getCorsConfigurations, getCorsProcessor, getHandler, getOrder, getPathHelper, getPathMatcher, setCorsConfigurations, setCorsProcessor, setOrder, setPathHelper, setPathMatcher, setUrlDecode
getApplicationContext, getMessageSourceAccessor, initApplicationContext, initApplicationContext, isContextRequired, requiredContextClass, setApplicationContext
private boolean useSuffixPatternMatch
private boolean useRegisteredSuffixPatternMatch
private boolean useTrailingSlashMatch
private RequestedContentTypeResolver contentTypeResolver
private StringValueResolver embeddedValueResolver
private RequestMappingInfo.BuilderConfiguration config
public void setUseSuffixPatternMatch(boolean useSuffixPatternMatch)
The default value is true
.
Note: when using suffix pattern matching it's usually
preferable to be explicit about what is and isn't an extension so rather
than setting this property consider using
setUseRegisteredSuffixPatternMatch(boolean)
instead.
public void setUseRegisteredSuffixPatternMatch(boolean useRegisteredSuffixPatternMatch)
RequestedContentTypeResolver
. 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 "true".
public void setUseTrailingSlashMatch(boolean useTrailingSlashMatch)
The default value is true
.
public void setContentTypeResolver(RequestedContentTypeResolver contentTypeResolver)
RequestedContentTypeResolver
to use to determine requested media types.
If not set, the default constructor is used.public void setEmbeddedValueResolver(StringValueResolver resolver)
EmbeddedValueResolverAware
setEmbeddedValueResolver
in interface EmbeddedValueResolverAware
public void afterPropertiesSet()
AbstractHandlerMethodMapping
afterPropertiesSet
in interface InitializingBean
afterPropertiesSet
in class AbstractHandlerMethodMapping<RequestMappingInfo>
public boolean useSuffixPatternMatch()
public boolean useRegisteredSuffixPatternMatch()
public boolean useTrailingSlashMatch()
public RequestedContentTypeResolver getContentTypeResolver()
RequestedContentTypeResolver
.public java.util.Set<java.lang.String> getFileExtensions()
protected boolean isHandler(java.lang.Class<?> beanType)
Controller
annotation.isHandler
in class AbstractHandlerMethodMapping<RequestMappingInfo>
beanType
- the type of the bean being checkedprotected RequestMappingInfo getMappingForMethod(java.lang.reflect.Method method, java.lang.Class<?> handlerType)
RequestMapping
annotations to create
the RequestMappingInfo.getMappingForMethod
in class AbstractHandlerMethodMapping<RequestMappingInfo>
method
- the method to provide a mapping forhandlerType
- the handler type, possibly a sub-type of the method's
declaring classnull
if the method
does not have a @RequestMapping
annotation.getCustomMethodCondition(Method)
,
getCustomTypeCondition(Class)
private RequestMappingInfo createRequestMappingInfo(java.lang.reflect.AnnotatedElement element)
createRequestMappingInfo(RequestMapping, RequestCondition)
,
supplying the appropriate custom RequestCondition
depending on whether
the supplied annotatedElement
is a class or method.protected RequestCondition<?> getCustomTypeCondition(java.lang.Class<?> handlerType)
RequestCondition
can 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
AbstractRequestCondition
for custom condition types and using
CompositeRequestCondition
to provide multiple custom conditions.
handlerType
- the handler type for which to create the conditionnull
protected RequestCondition<?> getCustomMethodCondition(java.lang.reflect.Method method)
RequestCondition
can 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
AbstractRequestCondition
for custom condition types and using
CompositeRequestCondition
to provide multiple custom conditions.
method
- the handler method for which to create the conditionnull
protected RequestMappingInfo createRequestMappingInfo(RequestMapping requestMapping, RequestCondition<?> customCondition)
RequestMappingInfo
from the supplied
@RequestMapping
annotation, which is either
a directly declared annotation, a meta-annotation, or the synthesized
result of merging annotation attributes within an annotation hierarchy.protected java.lang.String[] resolveEmbeddedValuesInPatterns(java.lang.String[] patterns)
protected CorsConfiguration initCorsConfiguration(java.lang.Object handler, java.lang.reflect.Method method, RequestMappingInfo mappingInfo)
AbstractHandlerMethodMapping
initCorsConfiguration
in class AbstractHandlerMethodMapping<RequestMappingInfo>
private void updateCorsConfig(CorsConfiguration config, CrossOrigin annotation)
private java.lang.String resolveCorsAnnotationValue(java.lang.String value)