注释类型 MessageMapping
@Target({TYPE,METHOD}) @Retention(RUNTIME) @Documented public @interface MessageMapping
Annotation for mapping aMessageonto a message-handling method by matching the declaredpatternsto a destination extracted from the message. The annotation is supported at the type-level too, as a way of declaring a pattern prefix (or prefixes) across all class methods.@MessageMappingmethods support the following arguments:@Payloadmethod argument to extract the payload of a message and have it de-serialized to the declared target type.@Payloadarguments may also be annotated with Validation annotations such as@Validatedand will then have JSR-303 validation applied. Keep in mind the annotation is not required to be present as it is assumed by default for arguments not handled otherwise.@DestinationVariablemethod argument for access to template variable values extracted from the message destination, e.g./hotels/{hotel}. Variable values may also be converted from String to the declared method argument type, if needed.@Headermethod argument to extract a specific message header value and have aConverterapplied to it to convert the value to the declared target type.@Headersmethod argument that is also assignable toMapfor access to all headers.MessageHeadersmethod argument for access to all headers.MessageHeaderAccessormethod argument for access to all headers. In some processing scenarios, like STOMP over WebSocket, this may also be a specialization such asSimpMessageHeaderAccessor.Message<T>for access to body and headers with the body de-serialized if necessary to match the declared type.Principalmethod arguments are supported in some processing scenarios such as STOMP over WebSocket. It reflects the authenticated user.
Return value handling depends on the processing scenario:
- STOMP over WebSocket -- the value is turned into a message and sent to a default response destination or to a custom destination specified with an
@SendToor@SendToUserannotation. - RSocket -- the response is used to reply to the stream request.
Specializations of this annotation include
@SubscribeMapping(e.g. STOMP subscriptions) and@ConnectMapping(e.g. RSocket connections). Both narrow the primary mapping further and also match against the message type. Both can be combined with a type-level@MessageMappingthat declares a common pattern prefix (or prefixes).For further details on the use of this annotation in different contexts, see the following sections of the Spring Framework reference:
- STOMP over WebSocket "Annotated Controllers".
- RSocket "Annotated Responders".
NOTE: When using controller interfaces (e.g. for AOP proxying), make sure to consistently put all your mapping annotations - such as
@MessageMappingand@SubscribeMapping- on the controller interface rather than on the implementation class.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev
- 另请参阅:
SimpAnnotationMethodMessageHandler,RSocketMessageHandler
元素详细资料
value
String[] value
Destination-based mapping expressed by this annotation.For STOMP over WebSocket messages this is
AntPathMatcher-style patterns matched against the STOMP destination of the message.for RSocket this is either
AntPathMatcherorPathPatternbased pattern, depending on which is configured, matched to the route of the stream request.If no patterns are configured, the mapping matches all destinations.
- 默认值:
- {}