类 MessageMappingMessageHandler
- java.lang.Object
- org.springframework.messaging.handler.invocation.reactive.AbstractMethodMessageHandler<CompositeMessageCondition>
- org.springframework.messaging.handler.annotation.reactive.MessageMappingMessageHandler
- 所有已实现的接口:
Aware
,BeanNameAware
,InitializingBean
,ApplicationContextAware
,EmbeddedValueResolverAware
,ReactiveMessageHandler
- 直接已知子类:
RSocketMessageHandler
public class MessageMappingMessageHandler extends AbstractMethodMessageHandler<CompositeMessageCondition> implements EmbeddedValueResolverAware
Extension ofAbstractMethodMessageHandler
for reactive, non-blocking handling of messages via@MessageMapping
methods. By default such methods are detected in@Controller
Spring beans but that can be changed viaAbstractMethodMessageHandler.setHandlerPredicate(Predicate)
.Payloads for incoming messages are decoded through the configured
setDecoders(List)
decoders, with the help ofPayloadMethodArgumentResolver
.There is no default handling for return values but
AbstractMethodMessageHandler.setReturnValueHandlerConfigurer(org.springframework.messaging.handler.invocation.reactive.ReturnValueHandlerConfigurer)
can be used to configure custom return value handlers. Sub-classes may also overrideinitReturnValueHandlers()
to set up default return value handlers.- 从以下版本开始:
- 5.2
- 作者:
- Rossen Stoyanchev
- 另请参阅:
AbstractEncoderMethodReturnValueHandler
字段概要
从类继承的字段 org.springframework.messaging.handler.invocation.reactive.AbstractMethodMessageHandler
logger
构造器概要
构造器 构造器 说明 MessageMappingMessageHandler()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.protected AbstractExceptionHandlerMethodResolver
createExceptionMethodResolverFor(Class<?> beanType)
Create a concrete instance ofAbstractExceptionHandlerMethodResolver
that finds exception handling methods based on some criteria, e.g. based on the presence of@MessageExceptionHandler
.protected CompositeMessageCondition
getCondition(AnnotatedElement element)
Determine the mapping condition for the given annotated element.ConversionService
getConversionService()
Return the configured ConversionService.List<? extends Decoder<?>>
getDecoders()
Return the configured decoders.protected RouteMatcher.Route
getDestination(Message<?> message)
Extract the destination from the given message.protected Set<String>
getDirectLookupMappings(CompositeMessageCondition mapping)
Return String-based destinations for the given mapping, if any, that can be used to find matches with a direct lookup (i.e. non-patterns).protected Comparator<CompositeMessageCondition>
getMappingComparator(Message<?> message)
Return a comparator for sorting matching mappings.protected CompositeMessageCondition
getMappingForMethod(Method method, Class<?> handlerType)
Obtain the mapping for the given method, if any.protected CompositeMessageCondition
getMatchingMapping(CompositeMessageCondition mapping, Message<?> message)
Check if a mapping matches the current message and return a possibly new mapping with conditions relevant to the current request.RouteMatcher
getRouteMatcher()
Return theRouteMatcher
used to map messages to handlers.Validator
getValidator()
Return the configured Validator instance.protected reactor.core.publisher.Mono<Void>
handleMatch(CompositeMessageCondition mapping, HandlerMethod handlerMethod, Message<?> message)
protected List<? extends HandlerMethodArgumentResolver>
initArgumentResolvers()
Return the list of argument resolvers to use.protected List<? extends HandlerMethodReturnValueHandler>
initReturnValueHandlers()
Return the list of return value handlers to use.protected RouteMatcher
obtainRouteMatcher()
Obtain theRouteMatcher
for actual use.protected String[]
processDestinations(String[] destinations)
Resolve placeholders in the given destinations.void
setConversionService(ConversionService conversionService)
Configure aConversionService
to use for type conversion of String based values, e.g. in destination variables or headers.void
setDecoders(List<? extends Decoder<?>> decoders)
Configure the decoders to use for incoming payloads.void
setEmbeddedValueResolver(StringValueResolver resolver)
Set the StringValueResolver to use for resolving embedded definition values.void
setRouteMatcher(RouteMatcher routeMatcher)
Set theRouteMatcher
to use for mapping messages to handlers based on the route patterns they're configured with.void
setValidator(Validator validator)
Set the Validator instance used for validating@Payload
arguments.从类继承的方法 org.springframework.messaging.handler.invocation.reactive.AbstractMethodMessageHandler
detectHandlerMethods, extendMapping, getApplicationContext, getArgumentResolverConfigurer, getArgumentResolvers, getBeanName, getDestinationLookup, getHandlerMethods, getHandlerPredicate, getReactiveAdapterRegistry, getReturnValueHandlerConfigurer, handleMessage, handleNoMatch, registerExceptionHandlerAdvice, registerHandlerMethod, setApplicationContext, setArgumentResolverConfigurer, setBeanName, setHandlerPredicate, setHandlers, setReactiveAdapterRegistry, setReturnValueHandlerConfigurer
构造器详细资料
MessageMappingMessageHandler
public MessageMappingMessageHandler()
方法详细资料
setDecoders
public void setDecoders(List<? extends Decoder<?>> decoders)
Configure the decoders to use for incoming payloads.
getDecoders
public List<? extends Decoder<?>> getDecoders()
Return the configured decoders.
setValidator
public void setValidator(@Nullable Validator validator)
Set the Validator instance used for validating@Payload
arguments.
getValidator
@Nullable public Validator getValidator()
Return the configured Validator instance.
setRouteMatcher
public void setRouteMatcher(@Nullable RouteMatcher routeMatcher)
Set theRouteMatcher
to use for mapping messages to handlers based on the route patterns they're configured with.By default,
SimpleRouteMatcher
is used, backed byAntPathMatcher
with "." as separator. For greater efficiency consider using thePathPatternRouteMatcher
fromspring-web
instead.
getRouteMatcher
@Nullable public RouteMatcher getRouteMatcher()
Return theRouteMatcher
used to map messages to handlers. May benull
before the component is initialized.
obtainRouteMatcher
protected RouteMatcher obtainRouteMatcher()
Obtain theRouteMatcher
for actual use.- 返回:
- the RouteMatcher (never
null
) - 抛出:
IllegalStateException
- in case of no RouteMatcher set- 从以下版本开始:
- 5.0
setConversionService
public void setConversionService(ConversionService conversionService)
Configure aConversionService
to use for type conversion of String based values, e.g. in destination variables or headers.By default
DefaultFormattingConversionService
is used.- 参数:
conversionService
- the conversion service to use
getConversionService
public ConversionService getConversionService()
Return the configured ConversionService.
setEmbeddedValueResolver
public void setEmbeddedValueResolver(StringValueResolver resolver)
从接口复制的说明:EmbeddedValueResolverAware
Set the StringValueResolver to use for resolving embedded definition values.
afterPropertiesSet
public void afterPropertiesSet()
从接口复制的说明:InitializingBean
Invoked by the containingBeanFactory
after it has set all bean properties and satisfiedBeanFactoryAware
,ApplicationContextAware
etc.This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
initArgumentResolvers
protected List<? extends HandlerMethodArgumentResolver> initArgumentResolvers()
从类复制的说明:AbstractMethodMessageHandler
Return the list of argument resolvers to use.Subclasses should also take into account custom argument types configured via
AbstractMethodMessageHandler.setArgumentResolverConfigurer(org.springframework.messaging.handler.invocation.reactive.ArgumentResolverConfigurer)
.
initReturnValueHandlers
protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers()
从类复制的说明:AbstractMethodMessageHandler
Return the list of return value handlers to use.Subclasses should also take into account custom return value types configured via
AbstractMethodMessageHandler.setReturnValueHandlerConfigurer(org.springframework.messaging.handler.invocation.reactive.ReturnValueHandlerConfigurer)
.
getMappingForMethod
protected CompositeMessageCondition getMappingForMethod(Method method, Class<?> handlerType)
从类复制的说明:AbstractMethodMessageHandler
Obtain the mapping for the given method, if any.- 指定者:
getMappingForMethod
在类中AbstractMethodMessageHandler<CompositeMessageCondition>
- 参数:
method
- the method to checkhandlerType
- the handler type, possibly a sub-type of the method's declaring class- 返回:
- the mapping, or
null
if the method is not mapped
getCondition
@Nullable protected CompositeMessageCondition getCondition(AnnotatedElement element)
Determine the mapping condition for the given annotated element.- 参数:
element
- the element to check- 返回:
- the condition, or
null
processDestinations
protected String[] processDestinations(String[] destinations)
Resolve placeholders in the given destinations.- 参数:
destinations
- the destinations- 返回:
- new array with the processed destinations or the same array
getDirectLookupMappings
protected Set<String> getDirectLookupMappings(CompositeMessageCondition mapping)
从类复制的说明:AbstractMethodMessageHandler
Return String-based destinations for the given mapping, if any, that can be used to find matches with a direct lookup (i.e. non-patterns).Note: This is completely optional. The mapping metadata for a subclass may support neither direct lookups, nor String based destinations.
getDestination
protected RouteMatcher.Route getDestination(Message<?> message)
从类复制的说明:AbstractMethodMessageHandler
Extract the destination from the given message.
getMatchingMapping
protected CompositeMessageCondition getMatchingMapping(CompositeMessageCondition mapping, Message<?> message)
从类复制的说明:AbstractMethodMessageHandler
Check if a mapping matches the current message and return a possibly new mapping with conditions relevant to the current request.- 指定者:
getMatchingMapping
在类中AbstractMethodMessageHandler<CompositeMessageCondition>
- 参数:
mapping
- the mapping to get a match formessage
- the message being handled- 返回:
- the match or
null
if there is no match
getMappingComparator
protected Comparator<CompositeMessageCondition> getMappingComparator(Message<?> message)
从类复制的说明:AbstractMethodMessageHandler
Return a comparator for sorting matching mappings. The returned comparator should sort 'better' matches higher.- 指定者:
getMappingComparator
在类中AbstractMethodMessageHandler<CompositeMessageCondition>
- 参数:
message
- the current Message- 返回:
- the comparator, never
null
createExceptionMethodResolverFor
protected AbstractExceptionHandlerMethodResolver createExceptionMethodResolverFor(Class<?> beanType)
从类复制的说明:AbstractMethodMessageHandler
Create a concrete instance ofAbstractExceptionHandlerMethodResolver
that finds exception handling methods based on some criteria, e.g. based on the presence of@MessageExceptionHandler
.- 指定者:
createExceptionMethodResolverFor
在类中AbstractMethodMessageHandler<CompositeMessageCondition>
- 参数:
beanType
- the class in which an exception occurred during handling- 返回:
- the resolver to use
handleMatch
protected reactor.core.publisher.Mono<Void> handleMatch(CompositeMessageCondition mapping, HandlerMethod handlerMethod, Message<?> message)