public final class IntegrationRequestMappingHandlerMapping extends RequestMappingHandlerMapping implements ApplicationListener<ContextRefreshedEvent>, DestructionAwareBeanPostProcessor
HandlerMapping
implementation that
detects and registers RequestMappingInfo
s for
HttpRequestHandlingEndpointSupport
from a Spring Integration HTTP configuration
of <inbound-channel-adapter/>
and <inbound-gateway/>
elements.
This class is automatically configured as a bean in the application context during the
parsing phase of the <inbound-channel-adapter/>
and <inbound-gateway/>
elements, if there is none registered, yet. However it can be configured as a regular
bean with appropriate configuration for RequestMappingHandlerMapping
.
It is recommended to have only one similar bean in the application context using the 'id'
HttpContextUtils.HANDLER_MAPPING_BEAN_NAME
.
In most cases, Spring MVC offers to configure Request Mapping via
org.springframework.stereotype.Controller
and
RequestMapping
.
That's why Spring MVC's Handler Mapping infrastructure relies on
HandlerMethod
, as different methods at the same
org.springframework.stereotype.Controller
user-class may have their own
RequestMapping
.
On the other side, all Spring Integration HTTP Inbound Endpoints are configured on
the basis of the same BaseHttpInboundEndpoint
class and there is no
single RequestMappingInfo
configuration without
HandlerMethod
in Spring MVC.
Accordingly IntegrationRequestMappingHandlerMapping
is a
HandlerMapping
compromise implementation between method-level annotations and component-level
(e.g. Spring Integration XML) configurations.
Starting with version 5.1, this class implements DestructionAwareBeanPostProcessor
to
register HTTP endpoints at runtime for dynamically declared beans, e.g. via
IntegrationFlowContext
, and unregister
them during the BaseHttpInboundEndpoint
destruction.
This class extends the Spring MVC RequestMappingHandlerMapping
class, inheriting
most of its logic, especially RequestMappingInfoHandlerMapping.handleNoMatch(java.util.Set, String, HttpServletRequest)
,
which throws a specific 4xx
error for the HTTP response, when mapping doesn't match
for some reason, preventing calls to any remaining mapping handlers in the application context.
For this reason, configuring the same path for both Spring Integration and
Spring MVC request mappings (e.g. `POST` in one and `GET` in the other) is not supported;
the MVC mapping will not be found.
RequestMapping
,
RequestMappingHandlerMapping
logger
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_ATTRIBUTE
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
IntegrationRequestMappingHandlerMapping() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
protected void |
detectHandlerMethods(Object handlerArg) |
protected CorsConfiguration |
getCorsConfiguration(Object handler,
HttpServletRequest request) |
protected HandlerExecutionChain |
getHandlerExecutionChain(Object handlerArg,
HttpServletRequest request) |
protected CorsConfiguration |
initCorsConfiguration(Object handler,
Method method,
RequestMappingInfo mappingInfo) |
protected boolean |
isHandler(Class<?> beanType) |
void |
onApplicationEvent(ContextRefreshedEvent event)
HttpRequestHandlingEndpointSupport s may depend on auto-created
requestChannel s, so MVC Handlers detection should be postponed
as late as possible. |
void |
postProcessBeforeDestruction(Object bean,
String beanName) |
Object |
postProcessBeforeInitialization(Object bean,
String beanName) |
boolean |
requiresDestruction(Object bean) |
createRequestMappingInfo, getContentNegotiationManager, getCustomMethodCondition, getCustomTypeCondition, getFileExtensions, getMappingForMethod, getPathPrefixes, match, registerHandlerMethod, registerMapping, resolveEmbeddedValuesInPatterns, setContentNegotiationManager, setEmbeddedValueResolver, setPathPrefixes, setUseRegisteredSuffixPatternMatch, setUseSuffixPatternMatch, setUseTrailingSlashMatch, useRegisteredSuffixPatternMatch, useSuffixPatternMatch, useTrailingSlashMatch
getDirectPaths, getHandlerInternal, getMappingComparator, getMappingPathPatterns, getMatchingMapping, handleMatch, handleNoMatch
createHandlerMethod, getCandidateBeanNames, getHandlerMethods, getHandlerMethodsForMappingName, getNamingStrategy, handlerMethodsInitialized, hasCorsConfigurationSource, initHandlerMethods, lookupHandlerMethod, processCandidateBean, setDetectHandlerMethodsInAncestorContexts, setHandlerMethodMappingNamingStrategy, unregisterMapping
adaptInterceptor, detectMappedInterceptors, extendInterceptors, formatMappingName, getAdaptedInterceptors, getCorsConfigurationSource, getCorsHandlerExecutionChain, getCorsProcessor, getDefaultHandler, getHandler, getMappedInterceptors, getOrder, getPathMatcher, getPatternParser, getUrlPathHelper, initApplicationContext, initInterceptors, initLookupPath, setAlwaysUseFullPath, setBeanName, setCorsConfigurations, setCorsConfigurationSource, setCorsProcessor, setDefaultHandler, setInterceptors, setOrder, setPathMatcher, setPatternParser, setRemoveSemicolonContent, setUrlDecode, setUrlPathHelper, usesPathPatterns
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, obtainApplicationContext, requiredContextClass, setApplicationContext
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forPayload
postProcessAfterInitialization
getPatternParser
getHandler, usesPathPatterns
public IntegrationRequestMappingHandlerMapping()
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
postProcessBeforeInitialization
in interface BeanPostProcessor
BeansException
public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException
postProcessBeforeDestruction
in interface DestructionAwareBeanPostProcessor
BeansException
public boolean requiresDestruction(Object bean)
requiresDestruction
in interface DestructionAwareBeanPostProcessor
protected boolean isHandler(Class<?> beanType)
isHandler
in class RequestMappingHandlerMapping
protected HandlerExecutionChain getHandlerExecutionChain(Object handlerArg, HttpServletRequest request)
getHandlerExecutionChain
in class AbstractHandlerMapping
protected CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequest request)
getCorsConfiguration
in class AbstractHandlerMethodMapping<RequestMappingInfo>
protected void detectHandlerMethods(Object handlerArg)
detectHandlerMethods
in class AbstractHandlerMethodMapping<RequestMappingInfo>
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo)
initCorsConfiguration
in class RequestMappingHandlerMapping
public void onApplicationEvent(ContextRefreshedEvent event)
HttpRequestHandlingEndpointSupport
s may depend on auto-created
requestChannel
s, so MVC Handlers detection should be postponed
as late as possible.onApplicationEvent
in interface ApplicationListener<ContextRefreshedEvent>
RequestMappingHandlerMapping.afterPropertiesSet()
public void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
afterPropertiesSet
in class RequestMappingHandlerMapping