类 SimpAnnotationMethodMessageHandler
- java.lang.Object
- org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler<SimpMessageMappingInfo>
- org.springframework.messaging.simp.annotation.support.SimpAnnotationMethodMessageHandler
- 所有已实现的接口:
Aware,InitializingBean,ApplicationContextAware,EmbeddedValueResolverAware,Lifecycle,Phased,SmartLifecycle,MessageHandler
public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHandler<SimpMessageMappingInfo> implements EmbeddedValueResolverAware, SmartLifecycle
A handler for messages delegating to@MessageMappingand@SubscribeMappingannotated methods.Supports Ant-style path patterns with template variables.
- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Brian Clozel, Juergen Hoeller
字段概要
从类继承的字段 org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler
logger
从接口继承的字段 org.springframework.context.SmartLifecycle
DEFAULT_PHASE
构造器概要
构造器 构造器 说明 SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate)Create an instance of SimpAnnotationMethodMessageHandler with the given message channels and broker messaging template.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected AbstractExceptionHandlerMethodResolvercreateExceptionHandlerMethodResolverFor(Class<?> beanType)ConversionServicegetConversionService()Return the configuredConversionService.protected StringgetDestination(Message<?> message)protected Set<String>getDirectLookupDestinations(SimpMessageMappingInfo mapping)Return destinations contained in the mapping that are not patterns and are therefore suitable for direct lookups.protected LoggetHandlerMethodLogger()Return a logger to set onInvocableHandlerMethod.MessageHeaderInitializergetHeaderInitializer()Return the configured header initializer.protected StringgetLookupDestination(String destination)Check whether the given destination (of an incoming message) matches to one of the configured destination prefixes and if so return the remaining portion of the destination after the matched prefix.protected Comparator<SimpMessageMappingInfo>getMappingComparator(Message<?> message)Return a comparator for sorting matching mappings.protected SimpMessageMappingInfogetMappingForMethod(Method method, Class<?> handlerType)Provide the mapping for a handler method.protected SimpMessageMappingInfogetMatchingMapping(SimpMessageMappingInfo mapping, Message<?> message)Check if a mapping matches the current message and return a possibly new mapping with conditions relevant to the current request.MessageConvertergetMessageConverter()Return the configuredMessageConverter.PathMatchergetPathMatcher()Return the PathMatcher implementation to use for matching destinations.protected LoggetReturnValueHandlerLogger()Return a logger to set onHandlerMethodReturnValueHandlerComposite.ValidatorgetValidator()Return the configured Validator instance.protected voidhandleMatch(SimpMessageMappingInfo mapping, HandlerMethod handlerMethod, String lookupDestination, Message<?> message)protected List<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 booleanisHandler(Class<?> beanType)Whether the given bean type should be introspected for messaging handling methods.booleanisRunning()Check whether this component is currently running.protected String[]resolveEmbeddedValuesInDestinations(String[] destinations)Resolve placeholder values in the given array of destinations.voidsetConversionService(ConversionService conversionService)Configure aConversionServiceto use when resolving method arguments, for example message header values.voidsetDestinationPrefixes(Collection<String> prefixes)When this property is configured only messages to destinations matching one of the configured prefixes are eligible for handling.voidsetEmbeddedValueResolver(StringValueResolver resolver)Set the StringValueResolver to use for resolving embedded definition values.voidsetHeaderInitializer(MessageHeaderInitializer headerInitializer)Configure aMessageHeaderInitializerto pass on toHandlerMethodReturnValueHandlersthat send messages from controller return values.voidsetMessageConverter(MessageConverter converter)Configure aMessageConverterto use to convert the payload of a message from its serialized form with a specific MIME type to an Object matching the target method parameter.voidsetPathMatcher(PathMatcher pathMatcher)Set the PathMatcher implementation to use for matching destinations against configured destination patterns.voidsetValidator(Validator validator)Set the Validator instance used for validating@Payloadarguments.voidstart()Start this component.voidstop()Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method.voidstop(Runnable callback)Indicates that a Lifecycle component must stop if it is currently running.从类继承的方法 org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler
afterPropertiesSet, createHandlerMethod, detectHandlerMethods, getApplicationContext, getArgumentResolvers, getCustomArgumentResolvers, getCustomReturnValueHandlers, getDestinationPrefixes, getExceptionHandlerMethod, getHandlerMethods, getReturnValueHandlers, handleMessage, handleMessageInternal, handleNoMatch, processHandlerMethodException, registerExceptionHandlerAdvice, registerHandlerMethod, setApplicationContext, setArgumentResolvers, setCustomArgumentResolvers, setCustomReturnValueHandlers, setReturnValueHandlers, toString
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
从接口继承的方法 org.springframework.context.SmartLifecycle
getPhase, isAutoStartup
构造器详细资料
SimpAnnotationMethodMessageHandler
public SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel, MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate)
Create an instance of SimpAnnotationMethodMessageHandler with the given message channels and broker messaging template.- 参数:
clientInboundChannel- the channel for receiving messages from clients (e.g. WebSocket clients)clientOutboundChannel- the channel for messages to clients (e.g. WebSocket clients)brokerTemplate- a messaging template to send application messages to the broker
方法详细资料
setDestinationPrefixes
public void setDestinationPrefixes(@Nullable Collection<String> prefixes)
When this property is configured only messages to destinations matching one of the configured prefixes are eligible for handling. When there is a match the prefix is removed and only the remaining part of the destination is used for method-mapping purposes.By default, no prefixes are configured in which case all messages are eligible for handling.
Destination prefixes are expected to be slash-separated Strings and therefore a slash is automatically appended where missing to ensure a proper prefix-based match (i.e. matching complete segments).
Note however that the remaining portion of a destination after the prefix may use a different separator (e.g. commonly "." in messaging) depending on the configured
PathMatcher.
setMessageConverter
public void setMessageConverter(MessageConverter converter)
Configure aMessageConverterto use to convert the payload of a message from its serialized form with a specific MIME type to an Object matching the target method parameter. The converter is also used when sending a message to the message broker.
getMessageConverter
public MessageConverter getMessageConverter()
Return the configuredMessageConverter.
setConversionService
public void setConversionService(ConversionService conversionService)
Configure aConversionServiceto use when resolving method arguments, for example message header values.By default,
DefaultFormattingConversionServiceis used.
getConversionService
public ConversionService getConversionService()
Return the configuredConversionService.
setPathMatcher
public void setPathMatcher(PathMatcher pathMatcher)
Set the PathMatcher implementation to use for matching destinations against configured destination patterns.By default,
AntPathMatcheris used.
getPathMatcher
public PathMatcher getPathMatcher()
Return the PathMatcher implementation to use for matching destinations.
getValidator
@Nullable public Validator getValidator()
Return the configured Validator instance.
setValidator
public void setValidator(@Nullable Validator validator)
Set the Validator instance used for validating@Payloadarguments.
setEmbeddedValueResolver
public void setEmbeddedValueResolver(StringValueResolver resolver)
从接口复制的说明:EmbeddedValueResolverAwareSet the StringValueResolver to use for resolving embedded definition values.
setHeaderInitializer
public void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitializer)
Configure aMessageHeaderInitializerto pass on toHandlerMethodReturnValueHandlersthat send messages from controller return values.By default, this property is not set.
getHeaderInitializer
@Nullable public MessageHeaderInitializer getHeaderInitializer()
Return the configured header initializer.
start
public final void start()
从接口复制的说明:LifecycleStart this component.Should not throw an exception if the component is already running.
In the case of a container, this will propagate the start signal to all components that apply.
- 指定者:
start在接口中Lifecycle- 另请参阅:
SmartLifecycle.isAutoStartup()
stop
public final void stop()
从接口复制的说明:LifecycleStop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. Consider implementingSmartLifecycleand itsstop(Runnable)variant when asynchronous stop behavior is necessary.Note that this stop notification is not guaranteed to come before destruction: On regular shutdown,
Lifecyclebeans will first receive a stop notification before the general destruction callbacks are being propagated; however, on hot refresh during a context's lifetime or on aborted refresh attempts, a given bean's destroy method will be called without any consideration of stop signals upfront.Should not throw an exception if the component is not running (not started yet).
In the case of a container, this will propagate the stop signal to all components that apply.
- 指定者:
stop在接口中Lifecycle- 另请参阅:
SmartLifecycle.stop(Runnable),DisposableBean.destroy()
stop
public final void stop(Runnable callback)
从接口复制的说明:SmartLifecycleIndicates that a Lifecycle component must stop if it is currently running.The provided callback is used by the
LifecycleProcessorto support an ordered, and potentially concurrent, shutdown of all components having a common shutdown order value. The callback must be executed after theSmartLifecyclecomponent does indeed stop.The
LifecycleProcessorwill call only this variant of thestopmethod; i.e.Lifecycle.stop()will not be called forSmartLifecycleimplementations unless explicitly delegated to within the implementation of this method.The default implementation delegates to
Lifecycle.stop()and immediately triggers the given callback in the calling thread. Note that there is no synchronization between the two, so custom implementations may at least want to put the same steps within their common lifecycle monitor (if any).- 指定者:
stop在接口中SmartLifecycle- 另请参阅:
Lifecycle.stop(),SmartLifecycle.getPhase()
isRunning
public final boolean isRunning()
从接口复制的说明:LifecycleCheck whether this component is currently running.In the case of a container, this will return
trueonly if all components that apply are currently running.
initArgumentResolvers
protected List<HandlerMethodArgumentResolver> initArgumentResolvers()
从类复制的说明:AbstractMethodMessageHandlerReturn the list of argument resolvers to use. Invoked only if the resolvers have not already been set viaAbstractMethodMessageHandler.setArgumentResolvers(java.util.List<org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver>).Subclasses should also take into account custom argument types configured via
AbstractMethodMessageHandler.setCustomArgumentResolvers(java.util.List<org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver>).
initReturnValueHandlers
protected List<? extends HandlerMethodReturnValueHandler> initReturnValueHandlers()
从类复制的说明:AbstractMethodMessageHandlerReturn the list of return value handlers to use. Invoked only if the return value handlers have not already been set viaAbstractMethodMessageHandler.setReturnValueHandlers(java.util.List<org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler>).Subclasses should also take into account custom return value types configured via
AbstractMethodMessageHandler.setCustomReturnValueHandlers(java.util.List<org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler>).
getReturnValueHandlerLogger
protected Log getReturnValueHandlerLogger()
从类复制的说明:AbstractMethodMessageHandlerReturn a logger to set onHandlerMethodReturnValueHandlerComposite.
getHandlerMethodLogger
protected Log getHandlerMethodLogger()
从类复制的说明:AbstractMethodMessageHandlerReturn a logger to set onInvocableHandlerMethod.
isHandler
protected boolean isHandler(Class<?> beanType)
从类复制的说明:AbstractMethodMessageHandlerWhether the given bean type should be introspected for messaging handling methods.
getMappingForMethod
@Nullable protected SimpMessageMappingInfo getMappingForMethod(Method method, Class<?> handlerType)
从类复制的说明:AbstractMethodMessageHandlerProvide the mapping for a handler method.- 指定者:
getMappingForMethod在类中AbstractMethodMessageHandler<SimpMessageMappingInfo>- 参数:
method- the method to provide a mapping forhandlerType- the handler type, possibly a sub-type of the method's declaring class- 返回:
- the mapping, or
nullif the method is not mapped
resolveEmbeddedValuesInDestinations
protected String[] resolveEmbeddedValuesInDestinations(String[] destinations)
Resolve placeholder values in the given array of destinations.- 返回:
- a new array with updated destinations
- 从以下版本开始:
- 4.2
getDirectLookupDestinations
protected Set<String> getDirectLookupDestinations(SimpMessageMappingInfo mapping)
从类复制的说明:AbstractMethodMessageHandlerReturn destinations contained in the mapping that are not patterns and are therefore suitable for direct lookups.
getDestination
@Nullable protected String getDestination(Message<?> message)
getLookupDestination
protected String getLookupDestination(@Nullable String destination)
从类复制的说明:AbstractMethodMessageHandlerCheck whether the given destination (of an incoming message) matches to one of the configured destination prefixes and if so return the remaining portion of the destination after the matched prefix.If there are no matching prefixes, return
null.If there are no destination prefixes, return the destination as is.
getMatchingMapping
@Nullable protected SimpMessageMappingInfo getMatchingMapping(SimpMessageMappingInfo mapping, Message<?> message)
从类复制的说明:AbstractMethodMessageHandlerCheck if a mapping matches the current message and return a possibly new mapping with conditions relevant to the current request.- 指定者:
getMatchingMapping在类中AbstractMethodMessageHandler<SimpMessageMappingInfo>- 参数:
mapping- the mapping to get a match formessage- the message being handled- 返回:
- the match or
nullif there is no match
getMappingComparator
protected Comparator<SimpMessageMappingInfo> getMappingComparator(Message<?> message)
从类复制的说明:AbstractMethodMessageHandlerReturn a comparator for sorting matching mappings. The returned comparator should sort 'better' matches higher.- 指定者:
getMappingComparator在类中AbstractMethodMessageHandler<SimpMessageMappingInfo>- 参数:
message- the current Message- 返回:
- the comparator, never
null
handleMatch
protected void handleMatch(SimpMessageMappingInfo mapping, HandlerMethod handlerMethod, String lookupDestination, Message<?> message)
createExceptionHandlerMethodResolverFor
protected AbstractExceptionHandlerMethodResolver createExceptionHandlerMethodResolverFor(Class<?> beanType)