org.springframework.web.reactive

## Class DispatcherHandler

- java.lang.Object
- - org.springframework.web.reactive.DispatcherHandler

- All Implemented Interfaces:
    Aware, ApplicationContextAware, PreFlightRequestHandler, WebHandler

      public class DispatcherHandler
      extends Object
      implements WebHandler, PreFlightRequestHandler, 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:

  - `HandlerMapping` -- map requests to handler objects
  - `HandlerAdapter` -- for using any handler interface
  - `HandlerResultHandler` -- process handler return values

  `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 Summary

    Constructors
    Constructor and Description
    `DispatcherHandler()` Create a new `DispatcherHandler` which needs to be configured with an `ApplicationContext` through `setApplicationContext(org.springframework.context.ApplicationContext)`.
    `DispatcherHandler(ApplicationContext applicationContext)` Create a new `DispatcherHandler` for the given `ApplicationContext`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `List<HandlerMapping>` | `getHandlerMappings()` Return all `HandlerMapping` beans detected by type in the `injected context` and also `sorted`.
    `reactor.core.publisher.Mono<Void>` | `handle(ServerWebExchange exchange)` Handle the web server exchange.
    `reactor.core.publisher.Mono<Void>` | `handlePreFlight(ServerWebExchange exchange)` Handle a pre-flight request by finding and applying the CORS configuration that matches the expected actual request.
    `protected void` | `initStrategies(ApplicationContext context)`
    `void` | `setApplicationContext(ApplicationContext applicationContext)` Set the ApplicationContext that this object runs in.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DispatcherHandler

          public DispatcherHandler()

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

    - #### DispatcherHandler

          public DispatcherHandler(ApplicationContext applicationContext)

      Create a new `DispatcherHandler` for the given `ApplicationContext`.
      Parameters:
        `applicationContext` - the application context to find the handler beans in

  - ### Method Detail

    - #### 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(ApplicationContext applicationContext)

      Description copied from interface: `ApplicationContextAware`
      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 `InitializingBean.afterPropertiesSet()` or a custom init-method. Invoked after `ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)`, `ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)` and `MessageSourceAware`, if applicable.

      Specified by:
        `setApplicationContext` in interface `ApplicationContextAware`
      Parameters:
        `applicationContext` - the ApplicationContext object to be used by this object
      See Also:
        `BeanInitializationException`

    - #### initStrategies

          protected void initStrategies(ApplicationContext context)

    - #### handle

          public reactor.core.publisher.Mono<Void> handle(ServerWebExchange exchange)

      Description copied from interface: `WebHandler`
      Handle the web server exchange.
      Specified by:
        `handle` in interface `WebHandler`
      Parameters:
        `exchange` - the current server exchange
      Returns:
        `Mono<Void>` to indicate when request handling is complete

    - #### handlePreFlight

          public reactor.core.publisher.Mono<Void> handlePreFlight(ServerWebExchange exchange)

      Description copied from interface: `PreFlightRequestHandler`
      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 `HttpStatus.FORBIDDEN`.
      Specified by:
        `handlePreFlight` in interface `PreFlightRequestHandler`
      Parameters:
        `exchange` - the exchange for the request
      Returns:
        a completion handle