Package org.springframework.web.reactive
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:
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:
-
WebHttpHandlerBuilder.applicationContext(ApplicationContext)
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a newDispatcherHandlerwhich needs to be configured with anApplicationContextthroughsetApplicationContext(org.springframework.context.ApplicationContext).DispatcherHandler(org.springframework.context.ApplicationContext applicationContext) Create a newDispatcherHandlerfor the givenApplicationContext. -
Method Summary
Modifier and TypeMethodDescriptionfinal List<HandlerMapping>reactor.core.publisher.Mono<Void>handle(org.springframework.web.server.ServerWebExchange exchange) reactor.core.publisher.Mono<Void>handlePreFlight(org.springframework.web.server.ServerWebExchange exchange) protected voidinitStrategies(org.springframework.context.ApplicationContext context) voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)
-
Constructor Details
-
DispatcherHandler
public DispatcherHandler()Create a newDispatcherHandlerwhich needs to be configured with anApplicationContextthroughsetApplicationContext(org.springframework.context.ApplicationContext). -
DispatcherHandler
public DispatcherHandler(org.springframework.context.ApplicationContext applicationContext) 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
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) - Specified by:
setApplicationContextin interfaceorg.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:
handlein interfaceorg.springframework.web.server.WebHandler
-
handlePreFlight
public reactor.core.publisher.Mono<Void> handlePreFlight(org.springframework.web.server.ServerWebExchange exchange) - Specified by:
handlePreFlightin interfaceorg.springframework.web.cors.reactive.PreFlightRequestHandler
-