| Feature | Spring MVC | Spring WebFlux |
|---|---|---|
| Programming model | Synchronous (traditional Java) | Asynchronous (reactive streams) |
| Controller return | String, ModelAndView, etc. | Mono<T>, Flux<T> |
| Server container | Tomcat, Jetty, Undertow (Servlet) | Netty (default), or Reactive Jetty |
| Use case | Simpler apps, low concurrency | High concurrency, streaming, SSE |
| Gateway support | ✅ spring-cloud-starter-gateway-server-webmvc | ✅ spring-cloud-starter-gateway-server-webflux |
Spring MVC:
@GetMapping("/hello")
public String hello() {
return "Hello";
}
Spring WebFlux:
@GetMapping("/hello")
public Mono<String> hello() {
return Mono.just("Hello");
}
| Concept | Servlet (Blocking) | Reactive (Non-blocking) |
|---|---|---|
| Request model | One thread per request | One thread handles many requests |
| I/O | Blocking (e.g., InputStream.read()) | Non-blocking (e.g., Mono/Flux) |
| Concurrency | Limited by thread pool | Scales better with fewer threads |
| Libraries | Uses Tomcat, Jetty, etc. | Uses Netty (no servlet container) |
| Memory/CPU | Higher resource usage | More efficient under high load |
| Example use | Traditional CRUD apps, MVC websites | Streaming APIs, high-concurrency APIs |