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.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 implementsApplicationContextAware
for access to the context it runs in. IfDispatcherHandler
is declared with the bean name "webHandler" it is discovered byWebHttpHandlerBuilder.applicationContext
which creates a processing chain together withWebFilter
,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 Description DispatcherHandler()
Create a newDispatcherHandler
which needs to be configured with anApplicationContext
throughsetApplicationContext(org.springframework.context.ApplicationContext)
.DispatcherHandler(ApplicationContext applicationContext)
Create a newDispatcherHandler
for 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 void
initStrategies(ApplicationContext context)
void
setApplicationContext(ApplicationContext applicationContext)
Set the ApplicationContext that this object runs in.
Constructor Detail
DispatcherHandler
public DispatcherHandler()
Create a newDispatcherHandler
which needs to be configured with anApplicationContext
throughsetApplicationContext(org.springframework.context.ApplicationContext)
.
DispatcherHandler
public DispatcherHandler(ApplicationContext applicationContext)
Create a newDispatcherHandler
for the givenApplicationContext
.- Parameters:
applicationContext
- the application context to find the handler beans in
Method Detail
getHandlerMappings
@Nullable public final List<HandlerMapping> getHandlerMappings()
Return allHandlerMapping
beans detected by type in theinjected context
and alsosorted
.Note: This method may return
null
if invoked prior tosetApplicationContext(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 afterResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)
,ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
andMessageSourceAware
, if applicable.- Specified by:
setApplicationContext
in 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:WebHandler
Handle the web server exchange.- Specified by:
handle
in interfaceWebHandler
- Parameters:
exchange
- the current server exchange- Returns:
Mono<Void>
to indicate when request handling is complete