Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Spring Boot Weblfux with embedded Tomcat

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?

like image 334
Kyle Chamberlin Avatar asked Apr 18 '17 12:04

Kyle Chamberlin


2 Answers

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.

like image 86
Brian Clozel Avatar answered Sep 26 '22 07:09

Brian Clozel


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>
like image 32
Thiagarajan Ramanathan Avatar answered Sep 22 '22 07:09

Thiagarajan Ramanathan