<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> </dependency>
@Configuration public class WebsocketConfig { @Bean public ServerEndpointExporter serverEndpointConfig() { return new ServerEndpointExporter(); } }
@Component @ServerEndpoint("/message") @Slf4j public class WebSocket { @OnOpen public void onOpen(Session session) { log.info("onOpen:{}", session.getId()); } @OnClose public void onClose(Session session) { log.info("onClose:{}", session.getId()); } @OnMessage public void onMessage(String message) { log.info("onMessage:{}", message); } @OnError public void one rror(Throwable cause, Session session) { log.info("onError:{}", session.getId()); } }
const ws = new WebSocket("ws://localhost:7777/message"); ws.onopen = function(){ console.log("open"); }
标签:info,websocket,log,void,session,整合,message,public,springboot From: https://www.cnblogs.com/itniwota/p/17459296.html