public class DispatcherHandler extends java.lang.Object implements WebHandler, ApplicationContextAware
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
s also designed to be a Spring bean itself and
implements ApplicationContextAware
for access to the context it runs
in. If DispatcherHandler
is declared with the bean name "webHandler"
it is discovered by WebHttpHandlerBuilder.applicationContext
which
creates a processing chain together with WebFilter
,
WebExceptionHandler
and others.
A DispatcherHandler
bean declaration is included in
@EnableWebFlux
configuration.
WebHttpHandlerBuilder.applicationContext(ApplicationContext)
Modifier and Type | Field and Description |
---|---|
private static java.lang.Exception |
HANDLER_NOT_FOUND_EXCEPTION |
private java.util.List<HandlerAdapter> |
handlerAdapters |
private java.util.List<HandlerMapping> |
handlerMappings |
private static Log |
logger |
private java.util.List<HandlerResultHandler> |
resultHandlers |
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 . |
Modifier and Type | Method and Description |
---|---|
java.util.List<HandlerMapping> |
getHandlerMappings()
|
private HandlerResultHandler |
getResultHandler(HandlerResult handlerResult) |
<any> |
handle(ServerWebExchange exchange)
Handle the web server exchange.
|
private <any> |
handleResult(ServerWebExchange exchange,
HandlerResult result) |
protected void |
initStrategies(ApplicationContext context) |
private <any> |
invokeHandler(ServerWebExchange exchange,
java.lang.Object handler) |
void |
setApplicationContext(ApplicationContext applicationContext)
Set the ApplicationContext that this object runs in.
|
private static final java.lang.Exception HANDLER_NOT_FOUND_EXCEPTION
private static final Log logger
@Nullable private java.util.List<HandlerMapping> handlerMappings
@Nullable private java.util.List<HandlerAdapter> handlerAdapters
@Nullable private java.util.List<HandlerResultHandler> resultHandlers
public DispatcherHandler()
DispatcherHandler
which needs to be configured with
an ApplicationContext
through setApplicationContext(org.springframework.context.ApplicationContext)
.public DispatcherHandler(ApplicationContext applicationContext)
DispatcherHandler
for the given ApplicationContext
.applicationContext
- the application context to find the handler beans in@Nullable public final java.util.List<HandlerMapping> getHandlerMappings()
HandlerMapping
beans detected by type in the
injected context
and also
sorted
.
Note: This method may return null
if invoked
prior to setApplicationContext(ApplicationContext)
.
null
public void setApplicationContext(ApplicationContext applicationContext)
ApplicationContextAware
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.
setApplicationContext
in interface ApplicationContextAware
applicationContext
- the ApplicationContext object to be used by this objectBeanInitializationException
protected void initStrategies(ApplicationContext context)
public <any> handle(ServerWebExchange exchange)
WebHandler
handle
in interface WebHandler
exchange
- the current server exchangeMono<Void>
to indicate when request handling is completeprivate <any> invokeHandler(ServerWebExchange exchange, java.lang.Object handler)
private <any> handleResult(ServerWebExchange exchange, HandlerResult result)
private HandlerResultHandler getResultHandler(HandlerResult handlerResult)