Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Web Reactive not working as war file deployed on Tomcat 8.5

I have Spring Boot (2.0.0 M5) application which provides some REST API. I'd like to implement this API using RouterFunctions.

While I'm running app using embedded Jetty everything works fine.

When I convert the app to WAR file (following documentation here) and deploy it to Tomcat 8.5 I always get 404 when trying to call any of the endpoints.

I can see in the log that endpoints are recognised:

[ost-startStop-1] s.w.r.r.m.a.RequestMappingHandlerMapping : Mapped "{[/say-hello],methods=[GET]}" onto java.lang.String com.example.demo.DemoController.test()
[ost-startStop-1] o.s.w.r.f.s.s.RouterFunctionMapping: Mapped /api => {
    /v1 => {
       /status -> 
          com.example.demo.DemoApplication$$Lambda$189/1904651750@5fdc83e
   }
}

But when calling curl -v http://localhost:8080/demo/say-hello or curl -v http://localhost:8080/demo/api/v1/status I see default Tomcat 404 page. The path is correct, I rename .war to demo.war before deploying it.

Did anybody come across similar issue? You can find the code here.

like image 318
belo Avatar asked Oct 12 '17 16:10

belo


People also ask

Can spring WebFlux run on Tomcat?

Spring WebFlux is supported on Tomcat, Jetty, Servlet 3.1+ containers, as well as on non-Servlet runtimes such as Netty and Undertow. Spring WebFlux is built on Project Reactor. Project Reactor is the implementation of Reactive Streams specification.

How do I run a war file in Tomcat 8?

Perhaps the simplest way to deploy a WAR file to Tomcat is to copy the file to Tomcat's webapps directory. Copy and paste WAR files into Tomcat's webapps directory to deploy them. Tomcat monitors this webapps directory for changes, and if it finds a new file there, it will attempt to deploy it.


1 Answers

I'm afraid the WAR deployment model is not supported in Spring Boot for WebFlux at the moment. Spring Framework does support that model (although I'm not sure it supports deploying an app to a non-root context).

You can always create an issue on the Spring Boot issue tracker, but I'm not sure this will be implemented, as deploying to a Servlet container is not the primary focus there (and you can't do that with Netty).

Quick note: adding @EnableWebFlux is a signal that you'd like to take the WebFlux configuration in your own hands and that Spring Boot should not auto-configure things for you in that space.

like image 90
Brian Clozel Avatar answered Nov 15 '22 00:11

Brian Clozel