@@ -10,18 +10,20 @@ to any controller. Moreover, as of 5.3, `@ExceptionHandler` methods in `@Control
10
10
can be used to handle exceptions from any `@Controller` or any other handler.
11
11
12
12
`@ControllerAdvice` is meta-annotated with `@Component` and therefore can be registered as
13
- a Spring bean through xref:core/beans/java/instantiating-container.adoc#beans-java-instantiating-container-scan[component scanning]
14
- . `@RestControllerAdvice` is meta-annotated with `@ControllerAdvice`
15
- and `@ResponseBody`, and that means `@ExceptionHandler` methods will have their return
16
- value rendered via response body message conversion, rather than via HTML views.
13
+ a Spring bean through xref:core/beans/java/instantiating-container.adoc#beans-java-instantiating-container-scan[component scanning].
14
+
15
+ `@RestControllerAdvice` is a shortcut annotation that combines `@ControllerAdvice`
16
+ with `@ResponseBody`, in effect simply an `@ControllerAdvice` whose exception handler
17
+ methods render to the response body.
17
18
18
19
On startup, `RequestMappingHandlerMapping` and `ExceptionHandlerExceptionResolver` detect
19
20
controller advice beans and apply them at runtime. Global `@ExceptionHandler` methods,
20
21
from an `@ControllerAdvice`, are applied _after_ local ones, from the `@Controller`.
21
22
By contrast, global `@ModelAttribute` and `@InitBinder` methods are applied _before_ local ones.
22
23
23
- The `@ControllerAdvice` annotation has attributes that let you narrow the set of controllers
24
- and handlers that they apply to. For example:
24
+ By default, both `@ControllerAdvice` and `@RestControllerAdvice` apply to any controller,
25
+ including `@Controller` and `@RestController`. Use attributes of the annotation to narrow
26
+ the set of controllers and handlers that they apply to. For example:
25
27
26
28
[tabs]
27
29
======
0 commit comments