Skip to content
Advertisement

How to deploy a Spring-Boot-Webflux application to Tomcat standalone server?

A normal spring-web application can be deployed to tomcat standalone as war file as follows:

@SpringBootApplication
public class MyApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(MyApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}

Question: how can I deploy such an application after migrating to spring-webflux to tomcat?

Docs say: https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-httphandler

To deploy as a WAR to any Servlet 3.1+ container, you can extend and include AbstractReactiveWebInitializer in the WAR. That class wraps an HttpHandler with ServletHttpHandlerAdapter and registers that as a Servlet.

So but there is no example how to.

I tried as follows, which gives an exception:

@SpringBootApplication
public class MyApplication extends AbstractReactiveWebInitializer {

    @Override
    protected Class<?>[] getConfigClasses() {
        return new Class[] {MyApplication.class};
    }

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}

Result:

MyApplication.java:13:8
java: cannot access javax.servlet.ServletException
  class file for javax.servlet.ServletException not found

Advertisement

Answer

This use case is not supported by the Spring Boot team, as explained in the reference documentation. Even if some features might work, you’ll find many limitations and bugs to this approach – and it seems you’ve started to experience just this.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement