WebSocketConfig.java 956 B

123456789101112131415161718192021222324252627
  1. package com.usky.webScoket;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.web.socket.config.annotation.EnableWebSocket;
  5. import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
  6. import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
  7. /**
  8. * @author buhao
  9. * @version WebSocketConfig.java, v 0.1 2019-10-17 15:43 buhao
  10. */
  11. @Configuration
  12. @EnableWebSocket
  13. public class WebSocketConfig implements WebSocketConfigurer {
  14. @Autowired
  15. private HttpAuthHandler httpAuthHandler;
  16. @Autowired
  17. private MyInterceptor myInterceptor;
  18. @Override
  19. public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
  20. registry
  21. .addHandler(httpAuthHandler, "/top/WS/alarmPush")
  22. .addInterceptors(myInterceptor)
  23. .setAllowedOrigins("*");
  24. }
  25. }