Class DispatcherHandler
- All Implemented Interfaces:
Aware
,ApplicationContextAware
,PreFlightRequestHandler
,WebHandler
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:
-
Constructor Summary
ConstructorDescriptionCreate 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
Modifier and TypeMethodDescriptionfinal @Nullable List<HandlerMapping>
reactor.core.publisher.Mono<Void>
handle
(ServerWebExchange exchange) Handle the web server exchange.reactor.core.publisher.Mono<Void>
handlePreFlight
(ServerWebExchange exchange) Handle a pre-flight request by finding and applying the CORS configuration that matches the expected actual request.protected void
initStrategies
(ApplicationContext context) void
setApplicationContext
(ApplicationContext applicationContext) Set the ApplicationContext that this object runs in.
-
Constructor Details
-
DispatcherHandler
public DispatcherHandler()Create a newDispatcherHandler
which needs to be configured with anApplicationContext
throughsetApplicationContext(org.springframework.context.ApplicationContext)
. -
DispatcherHandler
Create a newDispatcherHandler
for the givenApplicationContext
.- Parameters:
applicationContext
- the application context to find the handler beans in
-
-
Method Details
-
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
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:
-
initStrategies
-
handle
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
-
handlePreFlight
Description copied from interface:PreFlightRequestHandler
Handle a pre-flight request by finding and applying the CORS configuration that matches the expected actual request. As a result of handling, the response should be updated with CORS headers or rejected withHttpStatus.FORBIDDEN
.- Specified by:
handlePreFlight
in interfacePreFlightRequestHandler
- Parameters:
exchange
- the exchange for the request- Returns:
- a completion handle
-