From 97bfb75fbc8cf17a4d0eb892296fce4d44f42cd1 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 21 Jun 2019 12:45:08 +0300 Subject: [PATCH] Polish documentation for @ControllerAdvice in reference manual --- src/docs/asciidoc/web/webflux.adoc | 39 +++++++++++++++--------------- src/docs/asciidoc/web/webmvc.adoc | 29 +++++++++++----------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/docs/asciidoc/web/webflux.adoc b/src/docs/asciidoc/web/webflux.adoc index 4ac9d2e5e97..9cda2574dcc 100644 --- a/src/docs/asciidoc/web/webflux.adoc +++ b/src/docs/asciidoc/web/webflux.adoc @@ -2749,26 +2749,27 @@ an HTTP status code. === Controller Advice [.small]#<># -Typically, the `@ExceptionHandler`, `@InitBinder`, and `@ModelAttribute` methods apply within -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 -marked with `@ControllerAdvice` or `@RestControllerAdvice`. +Typically, the `@ExceptionHandler`, `@InitBinder`, and `@ModelAttribute` methods apply +within 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 annotated with `@ControllerAdvice` or `@RestControllerAdvice`. -`@ControllerAdvice` is marked with `@Component`, which means that such classes can be registered -as Spring beans through <>. -`@RestControllerAdvice` is also a meta-annotation marked with both `@ControllerAdvice` and -`@ResponseBody`, which essentially means `@ExceptionHandler` methods are rendered to the -response body through message conversion (versus view resolution or template rendering). +`@ControllerAdvice` is annotated with `@Component`, which means that such classes can be +registered as Spring beans through <>. `@RestControllerAdvice` is a composed annotation that is annotated +with both `@ControllerAdvice` and `@ResponseBody`, which essentially means +`@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. -Global `@ExceptionHandler` methods (from a `@ControllerAdvice`) are applied *after* local -ones (from the `@Controller`). By contrast, global `@ModelAttribute` and `@InitBinder` -methods are applied *before* local ones. +On startup, the infrastructure classes for `@RequestMapping` and `@ExceptionHandler` +methods detect Spring beans annotated with `@ControllerAdvice` and then apply their +methods at runtime. Global `@ExceptionHandler` methods (from a `@ControllerAdvice`) are +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, -as the following example shows: +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, as the following example shows: ==== [source,java,indent=0] @@ -2788,8 +2789,8 @@ as the following example shows: ---- ==== -The preceding selectors are evaluated at runtime and may negatively impact -performance if you use them extensively. See the +The selectors in the preceding example are evaluated at runtime and may negatively impact +performance if used extensively. See the {api-spring-framework}/web/bind/annotation/ControllerAdvice.html[`@ControllerAdvice`] javadoc for more details. diff --git a/src/docs/asciidoc/web/webmvc.adoc b/src/docs/asciidoc/web/webmvc.adoc index 20dc39f1872..44345bcdd90 100644 --- a/src/docs/asciidoc/web/webmvc.adoc +++ b/src/docs/asciidoc/web/webmvc.adoc @@ -3257,23 +3257,24 @@ necessary methods, and declare it as a Spring bean. Typically `@ExceptionHandler`, `@InitBinder`, and `@ModelAttribute` methods apply within 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 -marked with `@ControllerAdvice` or `@RestControllerAdvice`. +annotated with `@ControllerAdvice` or `@RestControllerAdvice`. -`@ControllerAdvice` is marked with `@Component`, which means such classes can be registered -as Spring beans through <>. -`@RestControllerAdvice` is also a meta-annotation marked with both `@ControllerAdvice` and -`@ResponseBody`, which essentially means `@ExceptionHandler` methods are rendered to the -response body through message conversion (versus view resolution or template rendering). +`@ControllerAdvice` is annotated with `@Component`, which means such classes can be +registered as Spring beans through <>. `@RestControllerAdvice` is a composed annotation that is annotated +with both `@ControllerAdvice` and `@ResponseBody`, which essentially means +`@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. -Global `@ExceptionHandler` methods (from a `@ControllerAdvice`) are applied _after_ local -ones (from the `@Controller`). By contrast, global `@ModelAttribute` and `@InitBinder` -methods are applied _before_ local ones. +On startup, the infrastructure classes for `@RequestMapping` and `@ExceptionHandler` +methods detect Spring beans annotated with `@ControllerAdvice` and then apply their +methods at runtime. Global `@ExceptionHandler` methods (from a `@ControllerAdvice`) are +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, -as the following example shows: +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, as the following example shows: ==== [source,java,indent=0]