spring-projects / spring-boot

Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss.
https://spring.io/projects/spring-boot
Apache License 2.0
75.12k stars 40.67k forks source link

Spring Reactive WebSocket does not work when Spring Web is present in the classpath. #23236

Closed vlaguduva closed 4 years ago

vlaguduva commented 4 years ago

Spring Reactive WebSocket does not work when Spring Web is present in the classpath. For example, pull this sample application https://github.com/faros/reactive-websockets; this sample works on Netty but when I tried to bring this on Tomcat by including spring-boot-starter-web in the pom.xml, the ws:// url started to return 404.

Steps to reproduce:

  1. Download the code: https://github.com/faros/reactive-websockets
  2. Include spring-boot-starter-web in the pom.xml
  3. mvn spring-boot:run
  4. App comes up on Tomcat
  5. try: http://localhost:8080/ on browser with F12 Dev Window on.
  6. Receive the error in the console: GET ws://localhost:8080/stringConverter [HTTP/1.1 404 82ms] Firefox canโ€™t establish a connection to the server at ws://localhost:8080/stringConverter.

Please note that I tried Tomcat update strategy unsuccessfully.

bclozel commented 4 years ago

spring-boot-starter-web brings in Spring MVC support - could you try to add spring-boot-starter-tomcat instead and report back here?

vlaguduva commented 4 years ago

spring-boot-starter-tomcat brings the reactive websocket up but the presence of spring-web bothers it, is there a reason why? can't a spring mvc project have reactive web sockets?

bclozel commented 4 years ago

spring-boot-starter-web brings both Spring MVC (the Servlet based web framework) and the Tomcat starter.

Whenever you choose to bring both spring-boot-starter-web and spring-boot-starter-webflux, Spring Boot auto-configures a Servlet-based application. Why? Because the common use case for that is to introduce the WebClient (from WebFlux) in a Spring MVC application. This is covered in the reference documentation.

Thanks!