Senior
On which application server does Spring WebFlux run? Why not Tomcat?
sobes.tech AI
Answer from AI
Spring WebFlux runs on application servers that support non-blocking, asynchronous input-output, such as Netty or Undertow. Tomcat is traditionally a blocking servlet container and is not suitable for the reactive WebFlux model, as it is based on the Servlet API, which does not inherently support non-blocking input-output.
Netty is an asynchronous, event-driven networking framework that is ideal for reactive applications, providing high performance and scalability without thread blocking.
Example configuration of WebFlux with Netty:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public NettyReactiveWebServerFactory nettyFactory() {
return new NettyReactiveWebServerFactory();
}
}
Thus, WebFlux uses Netty or other non-blocking servers to implement the reactive model, unlike Tomcat, which is oriented towards a blocking model.