0

I've been trying to set up a simple WebSocketHandler implementation but I've been running into this error javax.servlet.ServletException: No adapter for handler [turnip.gg.TurnipWebSocketHandler@5fdceca2]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler that I have not been able to solve.

Here's my configuration;

@Configuration
class WebSocket {
    @Autowired
    @Qualifier("TurnipWebSocket")
    private lateinit var handler: WebSocketHandler

    @Bean
    fun handlerMapping() = SimpleUrlHandlerMapping(mapOf("/socket" to handler), 1)

    @Bean
    fun handlerAdapter() = WebSocketHandlerAdapter()
}

And here's my simple WebSocketHandler

@Component("TurnipWebSocket")
class TurnipWebSocketHandler : WebSocketHandler {
    override fun handle(session: WebSocketSession): Mono<Void> = session.receive()... // Does other stuff with it
}

Thanks in advance!

Foxie
  • 117
  • 1
  • 7
  • Given that it's a `javax.servlet.ServletException` that's being thrown and the mention of `DispatcherServlet` in the error message, it looks like you're using servlets but `WebSocketHandler` and `WebSockerHandlerAdapter` are both part of Spring WebFlux. Your question's tags also suggest you're trying to use WebFlux. I would guess that you have a direct or transitive dependency on `spring-boot-starter-web`, but that's only a guess. Note the WebFlux's WebSocket support is part of `spring-webflux` so there's no need for a dependency on `spring-websocket` or `spring-boot-starter-websocket`. – Andy Wilkinson May 13 '20 at 20:45
  • @AndyWilkinson You are 100% correct, I had the `spring-boot-starter-websocket` dependency, which was importing the wrong SimpleUrlMapping. Changing this fixed it, thank you very much. – Foxie May 13 '20 at 21:29

0 Answers0