I\'m using Spring 3.2.5 without full new JSR-356 WebSockets support.
I would like to have singleton-bean reference in my @ServerEndpoint WebSocket serve
You have to add bean definition in the configuration of spring.
The solution i found to integrate JSR 356 websocket @ServerEndpoint is to turn off the Servlet container's scan for WebSocket endpoints by spring which can be done by registering @Bean in your Spring Configuration. By this spring not overrides normal JSR 356 websocket by spring STOMP websocket which is the part of the websocket.
@ServerEndpoint(value="/chatMessage")
public class ChatEndpoint{
// Normal websocket body goes here.
}
Adding Beans in your Configuration as:
@Configuration
public class WebsocketConfig{
@Bean
public ChatEndpoint chatEndpoint(){
return new ChatEndpoint();
}
// main one is ServerEndpointExporter which prevents Servlet container's scan for WebSocket
@Bean
public ServerEndpointExporter endpointExporter(){
return new ServerEndpointExporter();
}
}
This all done for you. But you should remove configurator = SpringConfigurator.class from @ServerEndpoint.
I am using Spring Websocket 4.0.0 and it works fine.
You can also see this Link.
If you alright then follow this Link also for concept.
Note that, Normally you should make websocket configuration separately from the main configuration of your spring.