public class DispatcherHandler extends java.lang.Object implements WebHandler, ApplicationContextAware
It can use any HandlerMapping implementation to control the routing of
requests to handler objects. HandlerMapping objects can be defined as beans in
the application context.
It can use any HandlerAdapter; this allows for using any handler interface.
HandlerAdapter objects can be added as beans in the application context.
It can use any HandlerResultHandler; this allows to process the result of
the request handling. HandlerResultHandler objects can be added as beans in the
application context.
| 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 |
|---|---|
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.
|
static HttpHandler |
toHttpHandler(ApplicationContext context)
Expose a dispatcher-based
HttpHandler for the given application context,
typically for direct registration with an engine adapter such as
ServletHttpHandlerAdapter. |
static WebHandler |
toWebHandler(ApplicationContext applicationContext)
Expose a dispatcher-based
WebHandler for the given application context,
typically for further configuration with filters and exception handlers through
a WebHttpHandlerBuilder. |
private static final java.lang.Exception HANDLER_NOT_FOUND_EXCEPTION
private static final Log logger
private java.util.List<HandlerMapping> handlerMappings
private java.util.List<HandlerAdapter> handlerAdapters
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 inpublic void setApplicationContext(ApplicationContext applicationContext)
ApplicationContextAwareInvoked 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 ApplicationContextAwareapplicationContext - the ApplicationContext object to be used by this objectBeanInitializationExceptionprotected void initStrategies(ApplicationContext context)
public <any> handle(ServerWebExchange exchange)
WebHandlerhandle in interface WebHandlerexchange - 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)
public static WebHandler toWebHandler(ApplicationContext applicationContext)
WebHandler for the given application context,
typically for further configuration with filters and exception handlers through
a WebHttpHandlerBuilder.applicationContext - the application context to find the handler beans inDispatcherHandler(ApplicationContext),
WebHttpHandlerBuilder.webHandler(org.springframework.web.server.WebHandler)public static HttpHandler toHttpHandler(ApplicationContext context)
HttpHandler for the given application context,
typically for direct registration with an engine adapter such as
ServletHttpHandlerAdapter.
Delegates to WebHttpHandlerBuilder.applicationContext(org.springframework.context.ApplicationContext) that
detects the target DispatcherHandler along with
WebFilters, and
WebExceptionHandlers in the given
ApplicationContext.
context - the application context to find the handler beans inDispatcherHandler(ApplicationContext),
HttpWebHandlerAdapter,
ServletHttpHandlerAdapter,
ReactorHttpHandlerAdapter,
RxNettyHttpHandlerAdapter,
UndertowHttpHandlerAdapter