Top Description Fields Constructors Methods
org.springframework.web.reactive

public Class DispatcherHandler

extends Object
implements WebHandler, PreFlightRequestHandler, ApplicationContextAware
Class Inheritance
All Implemented Interfaces
org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.Aware, org.springframework.web.cors.reactive.PreFlightRequestHandler, org.springframework.web.server.WebHandler
Imports
java.util.ArrayList, .Collections, .List, .Map, reactor.core.publisher.Flux, .Mono, org.springframework.beans.factory.BeanFactoryUtils, org.springframework.context.ApplicationContext, .ApplicationContextAware, org.springframework.core.annotation.AnnotationAwareOrderComparator, org.springframework.http.HttpStatus, org.springframework.lang.Nullable, org.springframework.util.ObjectUtils, org.springframework.web.cors.reactive.CorsUtils, .PreFlightRequestHandler, org.springframework.web.server.ResponseStatusException, .ServerWebExchange, .WebHandler, org.springframework.web.server.adapter.WebHttpHandlerBuilder

Central dispatcher for HTTP request handlers/controllers. Dispatches to registered handlers for processing a request, providing convenient mapping facilities.

DispatcherHandler discovers the delegate components it needs from Spring configuration. It detects the following in the application context:

DispatcherHandler is also designed to be a Spring bean itself and implements ApplicationContextAware for access to the context it runs in. If DispatcherHandler is declared as a bean with the name "webHandler", it is discovered by WebHttpHandlerBuilder#applicationContext(ApplicationContext) which puts together a processing chain together with WebFilter, WebExceptionHandler and others.

A DispatcherHandler bean declaration is included in @EnableWebFlux configuration.

Authors
Rossen Stoyanchev, Sebastien Deleuze, Juergen Hoeller
Since
5.0
See Also
WebHttpHandlerBuilder#applicationContext(ApplicationContext)

Field Summary

Modifier and TypeField and Description
private List<HandlerAdapter>
private List<HandlerMapping>
private List<HandlerResultHandler>

Constructor Summary

AccessConstructor and Description
public
DispatcherHandler()

Create a new DispatcherHandler which needs to be configured with an ApplicationContext through setApplicationContext.

public
DispatcherHandler(ApplicationContext
the application context to find the handler beans in
applicationContext
)

Create a new DispatcherHandler for the given ApplicationContext.

Method Summary

Modifier and TypeMethod and Description
private <R> Mono<R>
public final List<HandlerMapping>

Returns:

immutable list with the configured mappings or null
getHandlerMappings
()

Return all HandlerMapping beans detected by type in the injected context and also sorted.

public Mono<Void>
handle(ServerWebExchange
the current server exchange
exchange
)

Implements org.springframework.web.server.WebHandler.handle.

Handle the web server exchange.

public Mono<Void>
handlePreFlight(ServerWebExchange
the exchange for the request
exchange
)

Implements org.springframework.web.cors.reactive.PreFlightRequestHandler.handlePreFlight.

Handle a pre-flight request by finding and applying the CORS configuration that matches the expected actual request.

private Mono<Void>
private Mono<Void>
handleResult(ServerWebExchange exchange, HandlerResult handlerResult, String description)

private Mono<Void>
protected void
public void
setApplicationContext(ApplicationContext
the ApplicationContext object to be used by this object
applicationContext
)

Implements org.springframework.context.ApplicationContextAware.setApplicationContext.

Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

handlerAdaptersback to summary
private List<HandlerAdapter> handlerAdapters
Annotations
@Nullable
handlerMappingsback to summary
private List<HandlerMapping> handlerMappings
Annotations
@Nullable
resultHandlersback to summary
private List<HandlerResultHandler> resultHandlers
Annotations
@Nullable

Constructor Detail

DispatcherHandlerback to summary
public DispatcherHandler()

Create a new DispatcherHandler which needs to be configured with an ApplicationContext through setApplicationContext.

DispatcherHandlerback to summary
public DispatcherHandler(ApplicationContext applicationContext)

Create a new DispatcherHandler for the given ApplicationContext.

Parameters
applicationContext:ApplicationContext

the application context to find the handler beans in

Method Detail

createNotFoundErrorback to summary
private <R> Mono<R> createNotFoundError()
getHandlerMappingsback to summary
public final List<HandlerMapping> getHandlerMappings()

Return all HandlerMapping beans detected by type in the injected context and also sorted.

Note

This method may return null if invoked prior to setApplicationContext(ApplicationContext).

Returns:List<HandlerMapping>

immutable list with the configured mappings or null

Annotations
@Nullable
handleback to summary
public Mono<Void> handle(ServerWebExchange exchange)

Implements org.springframework.web.server.WebHandler.handle.

Doc from org.springframework.web.server.WebHandler.handle.

Handle the web server exchange.

Parameters
exchange:ServerWebExchange

the current server exchange

Returns:Mono<Void>

Mono<Void> to indicate when request handling is complete

Annotations
@Override
handlePreFlightback to summary
public Mono<Void> handlePreFlight(ServerWebExchange exchange)

Implements org.springframework.web.cors.reactive.PreFlightRequestHandler.handlePreFlight.

Doc from org.springframework.web.cors.reactive.PreFlightRequestHandler.handlePreFlight.

Handle a pre-flight request by finding and applying the CORS configuration that matches the expected actual request. As a result of handling, the response should be updated with CORS headers or rejected with org.springframework.http.HttpStatus#FORBIDDEN.

Parameters
exchange:ServerWebExchange

the exchange for the request

Returns:Mono<Void>

a completion handle

Annotations
@Override
handleRequestWithback to summary
private Mono<Void> handleRequestWith(ServerWebExchange exchange, Object handler)
handleResultback to summary
private Mono<Void> handleResult(ServerWebExchange exchange, HandlerResult handlerResult, String description)
handleResultMonoback to summary
private Mono<Void> handleResultMono(ServerWebExchange exchange, Mono<HandlerResult> resultMono)
initStrategiesback to summary
protected void initStrategies(ApplicationContext context)
setApplicationContextback to summary
public void setApplicationContext(ApplicationContext applicationContext)

Implements org.springframework.context.ApplicationContextAware.setApplicationContext.

Doc from org.springframework.context.ApplicationContextAware.setApplicationContext.

Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

Invoked after population of normal bean properties but before an init callback such as org.springframework.beans.factory.InitializingBean#afterPropertiesSet() or a custom init-method. Invoked after ResourceLoaderAware#setResourceLoader, ApplicationEventPublisherAware#setApplicationEventPublisher and MessageSourceAware, if applicable.

Parameters
applicationContext:ApplicationContext

the ApplicationContext object to be used by this object

Annotations
@Override