Backend Development 10 min read

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.

<code>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&lt;WebFluxProperties&gt; propsProvider) {
            HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(this.applicationContext).build();
            // optional base‑path handling omitted for brevity
            return httpHandler;
        }
    }
}
</code>

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.

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

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 :

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

During request processing, the chain looks like:

<code>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()
</code>

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 ).

<code>public class DispatcherHandler implements WebHandler {
    public Mono&lt;Void&gt; 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));
    }
}
</code>

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 :

<code>WebFilter1 -> WebFilter2 -> WebFilter3 -> DispatcherHandler.handle()
</code>
WebFlux filter chain diagram
WebFlux filter chain diagram
HttpWebHandlerAdapter processing flow
HttpWebHandlerAdapter processing flow
DispatcherHandler request handling
DispatcherHandler request handling
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

login 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.