9

I am attempting to use the WebFlux reactive types in a new Spring Boot App. I used the initializr at https://start.spring.io and selected the 2.0.0-SNAPSHOT version. I added the web reactive dependency and everything I did worked great. This was a really solid POC, the goal was how to make use of these types to modernize our APIs, to do this, we planned to slowly replace each portion of blocking and/or synchronous process and replace it with a non-blocking alternative implementation.

The problem I have is when I try to evolve my POC into something more akin to the services we have in production many things don't appear to be working. Now I understand that webflux is not GA yet, and that I shouldn't expect fully reactive support from all of the other spring projects yet. I do however recall when webflux was still called web-reactive that you could run on undertow/jetty/netty/tomcat/etc but now that I am using the webflux starter, everything defaults to netty, and I don't see the docs calling out how to change that to the embedded tomcat that our other services are currently using.

Is it still possible to use the spring-boot-starter-webflux with other app containers, or do I now need to manually bootstrap webflux to work with a something other than netty?

Kyle Chamberlin
  • 117
  • 1
  • 2
  • 6

2 Answers2

20

You can exclude spring-boot-starter-reactor-netty from the spring-boot-starter-webflux dependency and use spring-boot-starter-tomcat, spring-boot-starter-undertow or spring-boot-starter-jetty instead.

Brian Clozel
  • 51,523
  • 15
  • 149
  • 165
  • 2
    Is that still valid? I'll end up with missing classes like `Caused by: java.lang.NoClassDefFoundError: io/netty/buffer/Unpooled` – Michael Simons Jul 02 '17 at 18:50
  • Should be. Could you create an issue on https://github.com/spring-projects/spring-boot/issues with the complete stacktrace? – Brian Clozel Jul 03 '17 at 08:05
  • So is spring-boot-starter-reactor-netty contains a server? Is Netty a server itself? From here: https://stackoverflow.com/a/35749512/10894456 I see Netty is not a server, or am I wrong? – J.J. Beam Mar 13 '21 at 09:05
  • Yes this starter ships with a client and a server. Netty supports both cases. – Brian Clozel Mar 14 '21 at 12:00
5

If your objective is to use tomcat server then It is not necessary to exclude spring-boot-starter-reactor-netty. Adding spring boot starter tomcat will start the application in Tomcat server.

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
        <exclusions>
            <!-- Exclude the Netty dependency -->
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-reactor-netty</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- Use Tomcat instead -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>