注释类型 EnableWebSocket


  • @Retention(RUNTIME)
    @Target(TYPE)
    @Documented
    @Import(DelegatingWebSocketConfiguration.class)
    public @interface EnableWebSocket
    Add this annotation to an @Configuration class to configure processing WebSocket requests. A typical configuration would look like this:
     @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();
               }
    
               @Override
               public WebSocketHandler echoWebSocketHandler() {
             return new EchoWebSocketHandler();
         }
     }
     
    从以下版本开始:
    4.0
    作者:
    Rossen Stoyanchev