@@ -2749,26 +2749,27 @@ an HTTP status code.
2749
2749
=== Controller Advice
2750
2750
[.small]#<<web.adoc#mvc-ann-controller-advice, Same as in Spring MVC>>#
2751
2751
2752
- Typically, the `@ExceptionHandler`, `@InitBinder`, and `@ModelAttribute` methods apply within
2753
- the `@Controller` class (or class hierarchy) in which they are declared. If you want such
2754
- methods to apply more globally (across controllers), you can declare them in a class
2755
- marked with `@ControllerAdvice` or `@RestControllerAdvice`.
2756
-
2757
- `@ControllerAdvice` is marked with `@Component`, which means that such classes can be registered
2758
- as Spring beans through <<core.adoc#beans-java-instantiating-container-scan, component scanning>>.
2759
- `@RestControllerAdvice` is also a meta-annotation marked with both `@ControllerAdvice` and
2760
- `@ResponseBody`, which essentially means `@ExceptionHandler` methods are rendered to the
2761
- response body through message conversion (versus view resolution or template rendering).
2762
-
2763
- On startup, the infrastructure classes for `@RequestMapping` and `@ExceptionHandler` methods
2764
- detect Spring beans of type `@ControllerAdvice` and apply their methods at runtime.
2765
- Global `@ExceptionHandler` methods (from a `@ControllerAdvice`) are applied *after* local
2766
- ones (from the `@Controller`). By contrast, global `@ModelAttribute` and `@InitBinder`
2767
- methods are applied *before* local ones.
2768
-
2769
- By default `@ControllerAdvice` methods apply to every request (that is, all controllers), but
2770
- you can narrow that down to a subset of controllers through attributes on the annotation,
2771
- as the following example shows:
2752
+ Typically, the `@ExceptionHandler`, `@InitBinder`, and `@ModelAttribute` methods apply
2753
+ within the `@Controller` class (or class hierarchy) in which they are declared. If you
2754
+ want such methods to apply more globally (across controllers), you can declare them in a
2755
+ class annotated with `@ControllerAdvice` or `@RestControllerAdvice`.
2756
+
2757
+ `@ControllerAdvice` is annotated with `@Component`, which means that such classes can be
2758
+ registered as Spring beans through <<core.adoc#beans-java-instantiating-container-scan,
2759
+ component scanning>>. `@RestControllerAdvice` is a composed annotation that is annotated
2760
+ with both `@ControllerAdvice` and `@ResponseBody`, which essentially means
2761
+ `@ExceptionHandler` methods are rendered to the response body through message conversion
2762
+ (versus view resolution or template rendering).
2763
+
2764
+ On startup, the infrastructure classes for `@RequestMapping` and `@ExceptionHandler`
2765
+ methods detect Spring beans annotated with `@ControllerAdvice` and then apply their
2766
+ methods at runtime. Global `@ExceptionHandler` methods (from a `@ControllerAdvice`) are
2767
+ applied _after_ local ones (from the `@Controller`). By contrast, global `@ModelAttribute`
2768
+ and `@InitBinder` methods are applied _before_ local ones.
2769
+
2770
+ By default, `@ControllerAdvice` methods apply to every request (that is, all controllers),
2771
+ but you can narrow that down to a subset of controllers by using attributes on the
2772
+ annotation, as the following example shows:
2772
2773
2773
2774
====
2774
2775
[source,java,indent=0]
@@ -2788,8 +2789,8 @@ as the following example shows:
2788
2789
----
2789
2790
====
2790
2791
2791
- The preceding selectors are evaluated at runtime and may negatively impact
2792
- performance if you use them extensively. See the
2792
+ The selectors in the preceding example are evaluated at runtime and may negatively impact
2793
+ performance if used extensively. See the
2793
2794
{api-spring-framework}/web/bind/annotation/ControllerAdvice.html[`@ControllerAdvice`]
2794
2795
javadoc for more details.
2795
2796
0 commit comments