Johnson
Johnson

Reputation: 47

Spring 5 Websocket endpoint not reachable

I implemented a simple websocket endpoint in my Spring app (which is deployed in Tomcat) and I cannot reach it.

Configuration in my application context XML

<bean id="myWebSocketHandler" class="package.MyWebSocketHandler" />

<websocket:handlers>
    <websocket:mapping handler="myWebSocketHandler" path="/events"  />
</websocket:handlers>

I can see that MyWebSocketHandler is correctly picked up by Spring and initialized. However I am not able to reach the endpoint, using a websocket client and pointing it at ws://localhost:8080/my-context/events.

By "unable to reach the endpoint" I mean that I'm getting error 404, I know the url is correct because I have other REST endpoints in the same Spring application and I can reach them successfully.

I don't see anything wrong looking at the logs.

What could be the reason?

Upvotes: 0

Views: 49

Answers (1)

sascha10000
sascha10000

Reputation: 1240

Hey I had the same problem as there were only guides how to use stompjs to connect and so on. But I fixed it as spring boot enhanced the endpoint with /websocket at the end. That means maybe ws://localhost:8080/my-context/websocket or ws://localhost:8080/my-context/event/websocket may work. This is just an empty guess as it solved my problem a few years ago.

Upvotes: 0

Related Questions