0
votes

I'm attempting to build a basic Hello World Spring websockets app however I can't seem to hit the WebSocket endpoint, what am I missing?

I have added the TextWebSocketHandler, WebSocketConfigurer, and also have a AbstractContextLoaderInitializer which initialises a AnnotationConfigWebApplicationContext that scans the package that contain my websocket classes.

The websocket is called like so: ws://localhost:8080/client/websocket

Is there missing configuration? I don't want to use STOMP or socksjs. There is no other configuration in the app, perhaps further Spring config is required?

1

1 Answers

0
votes

Is your Configuration annotated with the @EnableWebSocket annotation? Do you register your WebSockethandler on the correct path?

@Configuration
@EnableWebSocket
public class WebSocketServerConfiguration implements WebSocketConfigurer {

    @Autowired
    protected MyWebSocketHandler webSocketHandler;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(webSocketHandler, "/as");
    }
}