Class DispatcherHandler

java.lang.Object
org.springframework.web.reactive.DispatcherHandler
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.web.cors.reactive.PreFlightRequestHandler, org.springframework.web.server.WebHandler

public class DispatcherHandler extends Object implements org.springframework.web.server.WebHandler, org.springframework.web.cors.reactive.PreFlightRequestHandler, org.springframework.context.ApplicationContextAware
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.

Since:
5.0
Author:
Rossen Stoyanchev, Sebastien Deleuze, Juergen Hoeller
See Also:
  • WebHttpHandlerBuilder.applicationContext(ApplicationContext)
  • Constructor Details

    • DispatcherHandler

      public DispatcherHandler()
      Create a new DispatcherHandler which needs to be configured with an ApplicationContext through setApplicationContext(org.springframework.context.ApplicationContext).
    • DispatcherHandler

      public DispatcherHandler(org.springframework.context.ApplicationContext applicationContext)
      Create a new DispatcherHandler for the given ApplicationContext.
      Parameters:
      applicationContext - the application context to find the handler beans in
  • Method Details

    • getHandlerMappings

      @Nullable 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:
      immutable list with the configured mappings or null
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
    • initStrategies

      protected void initStrategies(org.springframework.context.ApplicationContext context)
    • handle

      public reactor.core.publisher.Mono<Void> handle(org.springframework.web.server.ServerWebExchange exchange)
      Specified by:
      handle in interface org.springframework.web.server.WebHandler
    • handlePreFlight

      public reactor.core.publisher.Mono<Void> handlePreFlight(org.springframework.web.server.ServerWebExchange exchange)
      Specified by:
      handlePreFlight in interface org.springframework.web.cors.reactive.PreFlightRequestHandler