[Spring boot] Spring cloud gateway - intro - 2

brandon·2025년 6월 1일

spring-boot

목록 보기
9/15

Spring WebMVC vs Spring Webflux?

FeatureSpring MVCSpring WebFlux
Programming modelSynchronous (traditional Java)Asynchronous (reactive streams)
Controller returnString, ModelAndView, etc.Mono<T>, Flux<T>
Server containerTomcat, Jetty, Undertow (Servlet)Netty (default), or Reactive Jetty
Use caseSimpler apps, low concurrencyHigh concurrency, streaming, SSE
Gateway supportspring-cloud-starter-gateway-server-webmvcspring-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");
}

Reactive vs Servlet?

ConceptServlet (Blocking)Reactive (Non-blocking)
Request modelOne thread per requestOne thread handles many requests
I/OBlocking (e.g., InputStream.read())Non-blocking (e.g., Mono/Flux)
ConcurrencyLimited by thread poolScales better with fewer threads
LibrariesUses Tomcat, Jetty, etc.Uses Netty (no servlet container)
Memory/CPUHigher resource usageMore efficient under high load
Example useTraditional CRUD apps, MVC websitesStreaming APIs, high-concurrency APIs
profile
everything happens for a reason

0개의 댓글