spring-framework / org.springframework.web.socket.config.annotation / EnableWebSocket

EnableWebSocket

@Target([AnnotationTarget.CLASS, AnnotationTarget.FILE]) @Import(DelegatingWebSocketConfiguration) class EnableWebSocket

Add this annotation to an @Configuration class to configure processing WebSocket requests:

 @Configuration @EnableWebSocket public class MyWebSocketConfig { } 

Customize the imported configuration by implementing the WebSocketConfigurer interface:

 @Configuration @EnableWebSocket public class MyConfiguration implements WebSocketConfigurer { @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { registry.addHandler(echoWebSocketHandler(), "/echo").withSockJS(); } @Bean public WebSocketHandler echoWebSocketHandler() { return new EchoWebSocketHandler(); } } 

Author
Rossen Stoyanchev

Since
4.0

Constructors

<init>

EnableWebSocket()

Add this annotation to an @Configuration class to configure processing WebSocket requests:

 @Configuration @EnableWebSocket public class MyWebSocketConfig { } 

Customize the imported configuration by implementing the WebSocketConfigurer interface:

 @Configuration @EnableWebSocket public class MyConfiguration implements WebSocketConfigurer { @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { registry.addHandler(echoWebSocketHandler(), "/echo").withSockJS(); } @Bean public WebSocketHandler echoWebSocketHandler() { return new EchoWebSocketHandler(); } }