Class DispatcherHandler
- All Implemented Interfaces:
Aware, ApplicationContextAware, PreFlightRequestHandler, WebHandler
DispatcherHandler discovers the delegate components it needs from
Spring configuration. It detects the following in the application context:
HandlerMapping-- map requests to handler objectsHandlerAdapter-- for using any handler interfaceHandlerResultHandler-- 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:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a newDispatcherHandlerwhich needs to be configured with anApplicationContextthroughsetApplicationContext(ApplicationContext).DispatcherHandler(ApplicationContext applicationContext) Create a newDispatcherHandlerfor the givenApplicationContext. -
Method Summary
Modifier and TypeMethodDescriptionfinal @Nullable List<HandlerMapping> 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 voidinitStrategies(ApplicationContext context) voidsetApplicationContext(ApplicationContext applicationContext) Set the ApplicationContext that this object runs in.
-
Constructor Details
-
DispatcherHandler
public DispatcherHandler()Create a newDispatcherHandlerwhich needs to be configured with anApplicationContextthroughsetApplicationContext(ApplicationContext). -
DispatcherHandler
Create a newDispatcherHandlerfor the givenApplicationContext.- Parameters:
applicationContext- the application context to find the handler beans in
-
-
Method Details
-
getHandlerMappings
Return allHandlerMappingbeans detected by type in theinjected contextand alsosorted.Note: This method may return
nullif invoked prior tosetApplicationContext(ApplicationContext).- Returns:
- immutable list with the configured mappings or
null
-
setApplicationContext
Description copied from interface:ApplicationContextAwareSet 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 afterResourceLoaderAware.setResourceLoader(ResourceLoader),ApplicationEventPublisherAware.setApplicationEventPublisher(ApplicationEventPublisher)andMessageSourceAware, if applicable.- Specified by:
setApplicationContextin interfaceApplicationContextAware- Parameters:
applicationContext- the ApplicationContext object to be used by this object- See Also:
-
initStrategies
-
handle
Description copied from interface:WebHandlerHandle the web server exchange.- Specified by:
handlein interfaceWebHandler- Parameters:
exchange- the current server exchange- Returns:
Mono<Void>to indicate when request handling is complete
-
handlePreFlight
Description copied from interface:PreFlightRequestHandlerHandle 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 withHttpStatus.FORBIDDEN.- Specified by:
handlePreFlightin interfacePreFlightRequestHandler- Parameters:
exchange- the exchange for the request- Returns:
- a completion handle
-