Understanding Spring WebFlux Request Flow: From HttpHandler to DispatcherHandler

This article explains how Spring WebFlux automatically configures the HttpHandler, builds the HttpWebHandlerAdapter, chains WebFilters, and ultimately invokes the DispatcherHandler to process a request, detailing each class and method involved in the reactive request pipeline.

Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Understanding Spring WebFlux Request Flow: From HttpHandler to DispatcherHandler

1 Request Entry HttpHandler

Spring WebFlux provides an automatic configuration class HttpHandlerAutoConfiguration that creates the core HttpHandler bean used in a reactive web application.

public class HttpHandlerAutoConfiguration {
    @Configuration(proxyBeanMethods = false)
    public static class AnnotationConfig {
        private final ApplicationContext applicationContext;
        public AnnotationConfig(ApplicationContext applicationContext) {
            this.applicationContext = applicationContext;
        }
        @Bean
        public HttpHandler httpHandler(ObjectProvider<WebFluxProperties> propsProvider) {
            HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(this.applicationContext).build();
            // optional base‑path handling omitted for brevity
            return httpHandler;
        }
    }
}

The created HttpHandler is an instance of HttpWebHandlerAdapter, which is the core processor in the WebFlux environment.

2 HttpWebHandlerAdapter Creation

The HttpWebHandlerAdapter extends WebHandlerDecorator and implements HttpHandler. Its handle method delegates to the underlying WebHandler chain.

public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHandler {
    public HttpWebHandlerAdapter(WebHandler delegate) {
        super(delegate);
    }
    // handle method is inherited from WebHandlerDecorator
}

The delegate is built by WebHttpHandlerBuilder and consists of several decorator layers:

FilteringWebHandler – applies all WebFilter beans.

ExceptionHandlingWebHandler – adds global exception handling.

WebHandlerDecorator – base decorator providing getDelegate().

3 Delegated WebHandler Execution

The WebHandlerDecorator simply forwards the call to its delegate:

public class WebHandlerDecorator implements WebHandler {
    private final WebHandler delegate;
    public WebHandlerDecorator(WebHandler delegate) { this.delegate = delegate; }
    public WebHandler getDelegate() { return this.delegate; }
    public Mono<Void> handle(ServerWebExchange exchange) {
        return this.delegate.handle(exchange);
    }
}

During request processing, the chain looks like:

HttpWebHandlerAdapter.handle()
    -> getDelegate() // returns ExceptionHandlingWebHandler
    -> ExceptionHandlingWebHandler.handle()
        -> super.handle() // invokes FilteringWebHandler
            -> FilteringWebHandler.handle()
                -> DefaultWebFilterChain.filter(exchange)
                    -> (executes each WebFilter in order)
                    -> finally calls DispatcherHandler.handle()

4 DispatcherHandler Execution

The final handler, DispatcherHandler, resolves the appropriate HandlerMapping, obtains a HandlerAdapter, invokes the controller method, and processes the result through a series of HandlerResultHandler implementations (e.g., ResponseEntityResultHandler, ServerResponseResultHandler, ResponseBodyResultHandler, ViewResolutionResultHandler).

public class DispatcherHandler implements WebHandler {
    public Mono<Void> handle(ServerWebExchange exchange) {
        if (this.handlerMappings == null) return createNotFoundError();
        if (CorsUtils.isPreFlightRequest(exchange.getRequest())) return handlePreFlight(exchange);
        return Flux.fromIterable(this.handlerMappings)
            .concatMap(mapping -> mapping.getHandler(exchange))
            .next()
            .switchIfEmpty(createNotFoundError())
            .flatMap(handler -> invokeHandler(exchange, handler))
            .flatMap(result -> handleResult(exchange, result));
    }
}

The overall flow mirrors Spring MVC but operates in a fully reactive, non‑blocking manner.

5 Filter Chain Illustration

The three WebFilter beans are linked together to form a DefaultWebFilterChain:

WebFilter1 -> WebFilter2 -> WebFilter3 -> DispatcherHandler.handle()
WebFlux filter chain diagram
WebFlux filter chain diagram
HttpWebHandlerAdapter processing flow
HttpWebHandlerAdapter processing flow
DispatcherHandler request handling
DispatcherHandler request handling
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Backendjavareactivespring-webfluxHttpHandler
Spring Full-Stack Practical Cases
Written by

Spring Full-Stack Practical Cases

Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.