私はspring 4でwebsocket Javaを使用しようとしています。私はサーバーハンドラを作成しました。 は、ここに私のコード Websocket Spring 4
次、私が作成した
import java.util.logging.Logger;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.WebSocketMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;
public class ServerHandler extends TextWebSocketHandler{
\t
\t private Logger logger = Logger.getLogger(this.getClass().getName());
\t
\t @Override
\t public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
\t \t // TODO Auto-generated method stub
\t \t logger.info("Connection clodes with websocket server: session id " + session.getId());
\t }
\t
\t @Override
\t public void afterConnectionEstablished(WebSocketSession session) throws Exception {
\t \t // TODO Auto-generated method stub
\t \t logger.info("Connected user with websocket server: session id " + session.getId());
\t }
\t
\t @Override
\t public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
\t \t // TODO Auto-generated method stub
\t \t
\t \t super.handleMessage(session, message);
\t }
\t
\t @Override
\t public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
\t \t // TODO Auto-generated method stub
\t \t super.handleTransportError(session, exception);
\t }
}
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
@Configuration
@EnableWebSocket
public class WebsocketConfig implements WebSocketConfigurer{
\t
\t @Override
\t public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
\t \t registry.addHandler(myHandler(), "/websocket").withSockJS();
\t \t
\t }
\t
\t @Bean
public ServerHandler myHandler() {
return new ServerHandler();
}
\t
}
があり、私は、サーバー
var sock = new SockJS('http://localhost:9999/websocket');
に接続しようとしましたクライアント、404エラーが発生しました どこに問題がありますか?
この問題を解決する方法はありますか? –