Browse Source

Merge branch '5.1.x'

pull/23180/head
Sam Brannen 7 years ago
parent
commit
2f4c97cbdb
  1. 45
      src/docs/asciidoc/web/webflux.adoc
  2. 35
      src/docs/asciidoc/web/webmvc.adoc

45
src/docs/asciidoc/web/webflux.adoc

@ -2639,26 +2639,27 @@ an HTTP status code.
=== Controller Advice === Controller Advice
[.small]#<<web.adoc#mvc-ann-controller-advice, Same as in Spring MVC>># [.small]#<<web.adoc#mvc-ann-controller-advice, Same as in Spring MVC>>#
Typically, the `@ExceptionHandler`, `@InitBinder`, and `@ModelAttribute` methods apply within Typically, the `@ExceptionHandler`, `@InitBinder`, and `@ModelAttribute` methods apply
the `@Controller` class (or class hierarchy) in which they are declared. If you want such within the `@Controller` class (or class hierarchy) in which they are declared. If you
methods to apply more globally (across controllers), you can declare them in a class want such methods to apply more globally (across controllers), you can declare them in a
marked with `@ControllerAdvice` or `@RestControllerAdvice`. class annotated with `@ControllerAdvice` or `@RestControllerAdvice`.
`@ControllerAdvice` is marked with `@Component`, which means that such classes can be registered `@ControllerAdvice` is annotated with `@Component`, which means that such classes can be
as Spring beans through <<core.adoc#beans-java-instantiating-container-scan, component scanning>>. registered as Spring beans through <<core.adoc#beans-java-instantiating-container-scan,
`@RestControllerAdvice` is also a meta-annotation marked with both `@ControllerAdvice` and component scanning>>. `@RestControllerAdvice` is a composed annotation that is annotated
`@ResponseBody`, which essentially means `@ExceptionHandler` methods are rendered to the with both `@ControllerAdvice` and `@ResponseBody`, which essentially means
response body through message conversion (versus view resolution or template rendering). `@ExceptionHandler` methods are rendered to the response body through message conversion
(versus view resolution or template rendering).
On startup, the infrastructure classes for `@RequestMapping` and `@ExceptionHandler` methods
detect Spring beans of type `@ControllerAdvice` and apply their methods at runtime. On startup, the infrastructure classes for `@RequestMapping` and `@ExceptionHandler`
Global `@ExceptionHandler` methods (from a `@ControllerAdvice`) are applied *after* local methods detect Spring beans annotated with `@ControllerAdvice` and then apply their
ones (from the `@Controller`). By contrast, global `@ModelAttribute` and `@InitBinder` methods at runtime. Global `@ExceptionHandler` methods (from a `@ControllerAdvice`) are
methods are applied *before* local ones. applied _after_ local ones (from the `@Controller`). By contrast, global `@ModelAttribute`
and `@InitBinder` methods are applied _before_ local ones.
By default `@ControllerAdvice` methods apply to every request (that is, all controllers), but
you can narrow that down to a subset of controllers through attributes on the annotation, By default, `@ControllerAdvice` methods apply to every request (that is, all controllers),
as the following example shows: but you can narrow that down to a subset of controllers by using attributes on the
annotation, as the following example shows:
[source,java,indent=0] [source,java,indent=0]
[subs="verbatim,quotes"] [subs="verbatim,quotes"]
@ -2676,8 +2677,8 @@ as the following example shows:
public class ExampleAdvice3 {} public class ExampleAdvice3 {}
---- ----
The preceding selectors are evaluated at runtime and may negatively impact The selectors in the preceding example are evaluated at runtime and may negatively impact
performance if you use them extensively. See the performance if used extensively. See the
{api-spring-framework}/web/bind/annotation/ControllerAdvice.html[`@ControllerAdvice`] {api-spring-framework}/web/bind/annotation/ControllerAdvice.html[`@ControllerAdvice`]
javadoc for more details. javadoc for more details.

35
src/docs/asciidoc/web/webmvc.adoc

@ -3120,23 +3120,24 @@ necessary methods, and declare it as a Spring bean.
Typically `@ExceptionHandler`, `@InitBinder`, and `@ModelAttribute` methods apply within Typically `@ExceptionHandler`, `@InitBinder`, and `@ModelAttribute` methods apply within
the `@Controller` class (or class hierarchy) in which they are declared. If you want such the `@Controller` class (or class hierarchy) in which they are declared. If you want such
methods to apply more globally (across controllers), you can declare them in a class methods to apply more globally (across controllers), you can declare them in a class
marked with `@ControllerAdvice` or `@RestControllerAdvice`. annotated with `@ControllerAdvice` or `@RestControllerAdvice`.
`@ControllerAdvice` is marked with `@Component`, which means such classes can be registered `@ControllerAdvice` is annotated with `@Component`, which means such classes can be
as Spring beans through <<core.adoc#beans-java-instantiating-container-scan, component scanning>>. registered as Spring beans through <<core.adoc#beans-java-instantiating-container-scan,
`@RestControllerAdvice` is also a meta-annotation marked with both `@ControllerAdvice` and component scanning>>. `@RestControllerAdvice` is a composed annotation that is annotated
`@ResponseBody`, which essentially means `@ExceptionHandler` methods are rendered to the with both `@ControllerAdvice` and `@ResponseBody`, which essentially means
response body through message conversion (versus view resolution or template rendering). `@ExceptionHandler` methods are rendered to the response body through message conversion
(versus view resolution or template rendering).
On startup, the infrastructure classes for `@RequestMapping` and `@ExceptionHandler` methods
detect Spring beans of type `@ControllerAdvice` and then apply their methods at runtime. On startup, the infrastructure classes for `@RequestMapping` and `@ExceptionHandler`
Global `@ExceptionHandler` methods (from a `@ControllerAdvice`) are applied _after_ local methods detect Spring beans annotated with `@ControllerAdvice` and then apply their
ones (from the `@Controller`). By contrast, global `@ModelAttribute` and `@InitBinder` methods at runtime. Global `@ExceptionHandler` methods (from a `@ControllerAdvice`) are
methods are applied _before_ local ones. applied _after_ local ones (from the `@Controller`). By contrast, global `@ModelAttribute`
and `@InitBinder` methods are applied _before_ local ones.
By default, `@ControllerAdvice` methods apply to every request (that is, all controllers), but
you can narrow that down to a subset of controllers by using attributes on the annotation, By default, `@ControllerAdvice` methods apply to every request (that is, all controllers),
as the following example shows: but you can narrow that down to a subset of controllers by using attributes on the
annotation, as the following example shows:
[source,java,indent=0] [source,java,indent=0]
[subs="verbatim,quotes"] [subs="verbatim,quotes"]

Loading…
Cancel
Save