Class DispatcherHandler
- java.lang.Object
- org.springframework.web.reactive.DispatcherHandler
- All Implemented Interfaces:
Aware,ApplicationContextAware,WebHandler
public class DispatcherHandler extends Object implements WebHandler, ApplicationContextAware
Central dispatcher for HTTP request handlers/controllers. Dispatches to registered handlers for processing a request, providing convenient mapping facilities.DispatcherHandlerdiscovers 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
DispatcherHandleris also designed to be a Spring bean itself and implementsApplicationContextAwarefor access to the context it runs in. IfDispatcherHandleris declared with the bean name "webHandler" it is discovered byWebHttpHandlerBuilder.applicationContextwhich creates a processing chain together withWebFilter,WebExceptionHandlerand others.A
DispatcherHandlerbean declaration is included in@EnableWebFluxconfiguration.- Since:
- 5.0
- Author:
- Rossen Stoyanchev, Sebastien Deleuze, Juergen Hoeller
- See Also:
WebHttpHandlerBuilder.applicationContext(ApplicationContext)
Constructor Summary
Constructors Constructor Description DispatcherHandler()Create a newDispatcherHandlerwhich needs to be configured with anApplicationContextthroughsetApplicationContext(org.springframework.context.ApplicationContext).DispatcherHandler(ApplicationContext applicationContext)Create a newDispatcherHandlerfor the givenApplicationContext.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<HandlerMapping>getHandlerMappings()reactor.core.publisher.Mono<Void>handle(ServerWebExchange exchange)Handle the web server exchange.protected voidinitStrategies(ApplicationContext context)voidsetApplicationContext(ApplicationContext applicationContext)Set the ApplicationContext that this object runs in.
Constructor Detail
DispatcherHandler
public DispatcherHandler()
Create a newDispatcherHandlerwhich needs to be configured with anApplicationContextthroughsetApplicationContext(org.springframework.context.ApplicationContext).
DispatcherHandler
public DispatcherHandler(ApplicationContext applicationContext)
Create a newDispatcherHandlerfor the givenApplicationContext.- Parameters:
applicationContext- the application context to find the handler beans in
Method Detail
getHandlerMappings
@Nullable public final List<HandlerMapping> 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(ApplicationContext applicationContext)
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(org.springframework.core.io.ResourceLoader),ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)andMessageSourceAware, if applicable.- Specified by:
setApplicationContextin interfaceApplicationContextAware- 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: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