提交 e9187daa 编写于 作者: R Rossen Stoyanchev

Improvements to DispatcherHandler chapter

上级 314f3fc5
...@@ -481,7 +481,8 @@ implement one of the framework contracts listed in the table below. ...@@ -481,7 +481,8 @@ implement one of the framework contracts listed in the table below.
Spring WebFlux provides built-in implementations of these contracts but you can also Spring WebFlux provides built-in implementations of these contracts but you can also
customize, extend, or replace them. customize, extend, or replace them.
.Special bean types in the ApplicationContext [[webflux-special-beans-table]]
[cols="1,2", options="header"]
|=== |===
| Bean type| Explanation | Bean type| Explanation
...@@ -490,19 +491,43 @@ customize, extend, or replace them. ...@@ -490,19 +491,43 @@ customize, extend, or replace them.
which vary by `HandlerMapping` implementation -- annotated controllers, simple which vary by `HandlerMapping` implementation -- annotated controllers, simple
URL pattern mappings, etc. URL pattern mappings, etc.
The main `HandlerMapping` implementations are `RequestMappingHandlerMapping` based on
`@RequestMapping` annotated methods, `RouterFunctionMapping` based on functional
endpoint routes, and `SimpleUrlHandlerMapping` based on explicit registrations of URI
path patterns to handlers.
| HandlerAdapter | HandlerAdapter
| Helps the `DispatcherHandler` to invoke a handler mapped to a request regardless of | Help the `DispatcherHandler` to invoke a handler mapped to a request regardless of
how the handler is actually invoked. For example invoking an annotated controller how the handler is actually invoked. For example invoking an annotated controller
requires resolving various annotations. The main purpose of a `HandlerAdapter` is requires resolving annotations. The main purpose of a `HandlerAdapter` is to shield the
to shield the `DispatcherHandler` from such details. `DispatcherHandler` from such details.
| HandlerResultHandler | HandlerResultHandler
| Process the `HandlerResult` returned from a `HandlerAdapter`. | Process the result from the handler invocation and finalize the response.
The built-in `HandlerResultHandler` implementations are `ResponseEntityResultHandler`
supporting `ResponseEntity` return values, `ResponseBodyResultHandler`
supporting `@ResponseBody` methods, `ServerResponseResultHandler`
supporting the `ServerResponse` returned from functional endpoints, and
`ViewResolutionResultHandler` supporting rendering with a view and a model.
|=== |===
[[webflux-framework-config]]
=== Framework Config
[.small]#<<web.adoc#mvc-servlet-config,Same in Spring MVC>>#
The `DispatcherHandler` detects the special beans it needs in the `ApplicationContext`.
Applications can declare the special beans they wish to have. However most applications
will find a better starting point in the WebFlux Java config which provide a higher level
configuration API that in turn make the necessary bean declarations.
See <<webflux-config>> for more details.
[[webflux-dispatcher-handler-sequence]] [[webflux-dispatcher-handler-sequence]]
=== Processing sequence === Processing
[.small]#<<web.adoc#mvc-servlet-sequence,Same in Spring MVC>># [.small]#<<web.adoc#mvc-servlet-sequence,Same in Spring MVC>>#
The `DispatcherHandler` processes requests as follows: The `DispatcherHandler` processes requests as follows:
...@@ -574,7 +599,7 @@ rendering). ...@@ -574,7 +599,7 @@ rendering).
[[webflux-ann-requestmapping]] [[webflux-ann-requestmapping]]
=== Mapping Requests === Request Mapping
[.small]#<<web.adoc#mvc-ann-requestmapping,Same in Spring MVC>># [.small]#<<web.adoc#mvc-ann-requestmapping,Same in Spring MVC>>#
The `@RequestMapping` annotation is used to map requests to controllers methods. It has The `@RequestMapping` annotation is used to map requests to controllers methods. It has
......
...@@ -218,14 +218,14 @@ customize, extend, or replace them. ...@@ -218,14 +218,14 @@ customize, extend, or replace them.
The mapping is based on some criteria the details of which vary by `HandlerMapping` The mapping is based on some criteria the details of which vary by `HandlerMapping`
implementation. implementation.
The two main HandlerMapping implementations are `RequestMappingHandlerMapping` which The two main `HandlerMapping` implementations are `RequestMappingHandlerMapping` which
supports `@RequestMapping` annotated methods and `SimpleUrlHandlerMapping` which supports `@RequestMapping` annotated methods and `SimpleUrlHandlerMapping` which
maintains explicit registrations of URI path patterns to handlers. maintains explicit registrations of URI path patterns to handlers.
| HandlerAdapter | HandlerAdapter
| Helps the `DispatcherServlet` to invoke a handler mapped to a request regardless of | Help the `DispatcherServlet` to invoke a handler mapped to a request regardless of
how the handler is actually invoked. For example, invoking an annotated controller how the handler is actually invoked. For example, invoking an annotated controller
requires resolving various annotations. The main purpose of a `HandlerAdapter` is requires resolving annotations. The main purpose of a `HandlerAdapter` is
to shield the `DispatcherServlet` from such details. to shield the `DispatcherServlet` from such details.
| <<mvc-exceptionhandlers,HandlerExceptionResolver>> | <<mvc-exceptionhandlers,HandlerExceptionResolver>>
...@@ -233,15 +233,15 @@ customize, extend, or replace them. ...@@ -233,15 +233,15 @@ customize, extend, or replace them.
views, or other. See <<mvc-exceptionhandlers>>. views, or other. See <<mvc-exceptionhandlers>>.
| <<mvc-viewresolver,ViewResolver>> | <<mvc-viewresolver,ViewResolver>>
| Resolves logical String-based view names returned from a handler to an actual `View` | Resolve logical String-based view names returned from a handler to an actual `View`
to render to the response with. See <<mvc-viewresolver>> and <<mvc-view>>. to render to the response with. See <<mvc-viewresolver>> and <<mvc-view>>.
| <<mvc-localeresolver,LocaleResolver>>, <<mvc-timezone,LocaleContextResolver>> | <<mvc-localeresolver,LocaleResolver>>, <<mvc-timezone,LocaleContextResolver>>
| Resolves the `Locale` a client is using and possibly their time zone, in order to be able | Resolve the `Locale` a client is using and possibly their time zone, in order to be able
to offer internationalized views. See <<mvc-localeresolver>>. to offer internationalized views. See <<mvc-localeresolver>>.
| <<mvc-themeresolver,ThemeResolver>> | <<mvc-themeresolver,ThemeResolver>>
| Resolves themes your web application can use, for example, to offer personalized layouts. | Resolve themes your web application can use, for example, to offer personalized layouts.
See <<mvc-themeresolver>>. See <<mvc-themeresolver>>.
| <<mvc-multipart,MultipartResolver>> | <<mvc-multipart,MultipartResolver>>
...@@ -249,7 +249,7 @@ customize, extend, or replace them. ...@@ -249,7 +249,7 @@ customize, extend, or replace them.
the help of some multipart parsing library. See <<mvc-multipart>>. the help of some multipart parsing library. See <<mvc-multipart>>.
| <<mvc-flash-attributes,FlashMapManager>> | <<mvc-flash-attributes,FlashMapManager>>
| Stores and retrieves the "input" and the "output" `FlashMap` that can be used to pass | Store and retrieve the "input" and the "output" `FlashMap` that can be used to pass
attributes from one request to another, usually across a redirect. attributes from one request to another, usually across a redirect.
See <<mvc-flash-attributes>>. See <<mvc-flash-attributes>>.
|=== |===
...@@ -257,6 +257,8 @@ customize, extend, or replace them. ...@@ -257,6 +257,8 @@ customize, extend, or replace them.
[[mvc-servlet-config]] [[mvc-servlet-config]]
=== Framework Config === Framework Config
[.small]#<<web-reactive.adoc#webflux-framework-config,Same in Spring WebFlux>>#
For each type of special bean, the `DispatcherServlet` checks for the `WebApplicationContext` first. For each type of special bean, the `DispatcherServlet` checks for the `WebApplicationContext` first.
If there are no matching bean types, it falls back on the default types listed in If there are no matching bean types, it falls back on the default types listed in
https://github.com/spring-projects/spring-framework/blob/master/spring-webmvc/src/main/resources/org/springframework/web/servlet/DispatcherServlet.properties[DispatcherServlet.properties]. https://github.com/spring-projects/spring-framework/blob/master/spring-webmvc/src/main/resources/org/springframework/web/servlet/DispatcherServlet.properties[DispatcherServlet.properties].
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册