Currently there is no way for Spring's implementation of websocket endpoints to track session or provide appropriate websocket scope. Existing solution (WebSocketMessageBrokerConfigurer) takes into account only STOMP protocol which is defenitely not enough.

Comment From: wilkinsona

WebSocketMessageBrokerConfigurer is part of Spring Framework so I think this suggestion belongs in the Framework issue tracker. We'll transfer the issue.

Comment From: mahairod

Ok, I agree. No problem.

Comment From: Polve

I suppose this is related to #27631

Comment From: rstoyanchev

WebSocket scope requires establishing ThreadLocal context around the invocation of classes that need to use the scope. We can only do this if we are involved in the handling of messages. We can do it for STOMP around the invocation of @Controllers and channel interceptors, as documented in WebSocket scope, but we can't do the same for other scenarios.

Generally this shouldn't be hard to implement however. You just need to implement Scope and register it through a CustomScopeConfigurer bean. In the Scope implementation, get access to the WebSocketSession attributes in a static way through a ThreadLocal that you'll need to establish around the invocation of classes that use the scope. You can see SimpSessionScope for an example.