mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Provide @WebSocketScope annotation and public SCOPE_WEBSOCKET constant
Closes gh-35235
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
[[websocket-stomp-websocket-scope]]
|
||||
= WebSocket Scope
|
||||
|
||||
Each WebSocket session has a map of attributes. The map is attached as a header to
|
||||
inbound client messages and may be accessed from a controller method, as the following example shows:
|
||||
Each WebSocket session has a map of attributes. The map is attached as a header to inbound
|
||||
client messages and may be accessed from a controller method, as the following example shows:
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes"]
|
||||
----
|
||||
@@ -20,13 +20,13 @@ public class MyController {
|
||||
You can declare a Spring-managed bean in the `websocket` scope.
|
||||
You can inject WebSocket-scoped beans into controllers and any channel interceptors
|
||||
registered on the `clientInboundChannel`. Those are typically singletons and live
|
||||
longer than any individual WebSocket session. Therefore, you need to use a
|
||||
scope proxy mode for WebSocket-scoped beans, as the following example shows:
|
||||
longer than any individual WebSocket session. Therefore, you need to use
|
||||
WebSocket-scoped beans in proxy mode, conveniently defined with `@WebSocketScope`:
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes"]
|
||||
----
|
||||
@Component
|
||||
@Scope(scopeName = "websocket", proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
@WebSocketScope
|
||||
public class MyBean {
|
||||
|
||||
@PostConstruct
|
||||
|
||||
Reference in New Issue
Block a user