Skip to content

Commit 97bfb75

Browse files
committed
Polish documentation for @ControllerAdvice in reference manual
1 parent ad915f4 commit 97bfb75

File tree

2 files changed

+41
-39
lines changed

2 files changed

+41
-39
lines changed

src/docs/asciidoc/web/webflux.adoc

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,26 +2749,27 @@ an HTTP status code.
27492749
=== Controller Advice
27502750
[.small]#<<web.adoc#mvc-ann-controller-advice, Same as in Spring MVC>>#
27512751

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:
27722773

27732774
====
27742775
[source,java,indent=0]
@@ -2788,8 +2789,8 @@ as the following example shows:
27882789
----
27892790
====
27902791

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
27932794
{api-spring-framework}/web/bind/annotation/ControllerAdvice.html[`@ControllerAdvice`]
27942795
javadoc for more details.
27952796

src/docs/asciidoc/web/webmvc.adoc

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3257,23 +3257,24 @@ necessary methods, and declare it as a Spring bean.
32573257
Typically `@ExceptionHandler`, `@InitBinder`, and `@ModelAttribute` methods apply within
32583258
the `@Controller` class (or class hierarchy) in which they are declared. If you want such
32593259
methods to apply more globally (across controllers), you can declare them in a class
3260-
marked with `@ControllerAdvice` or `@RestControllerAdvice`.
3261-
3262-
`@ControllerAdvice` is marked with `@Component`, which means such classes can be registered
3263-
as Spring beans through <<core.adoc#beans-java-instantiating-container-scan, component scanning>>.
3264-
`@RestControllerAdvice` is also a meta-annotation marked with both `@ControllerAdvice` and
3265-
`@ResponseBody`, which essentially means `@ExceptionHandler` methods are rendered to the
3266-
response body through message conversion (versus view resolution or template rendering).
3267-
3268-
On startup, the infrastructure classes for `@RequestMapping` and `@ExceptionHandler` methods
3269-
detect Spring beans of type `@ControllerAdvice` and then apply their methods at runtime.
3270-
Global `@ExceptionHandler` methods (from a `@ControllerAdvice`) are applied _after_ local
3271-
ones (from the `@Controller`). By contrast, global `@ModelAttribute` and `@InitBinder`
3272-
methods are applied _before_ local ones.
3273-
3274-
By default, `@ControllerAdvice` methods apply to every request (that is, all controllers), but
3275-
you can narrow that down to a subset of controllers by using attributes on the annotation,
3276-
as the following example shows:
3260+
annotated with `@ControllerAdvice` or `@RestControllerAdvice`.
3261+
3262+
`@ControllerAdvice` is annotated with `@Component`, which means such classes can be
3263+
registered as Spring beans through <<core.adoc#beans-java-instantiating-container-scan,
3264+
component scanning>>. `@RestControllerAdvice` is a composed annotation that is annotated
3265+
with both `@ControllerAdvice` and `@ResponseBody`, which essentially means
3266+
`@ExceptionHandler` methods are rendered to the response body through message conversion
3267+
(versus view resolution or template rendering).
3268+
3269+
On startup, the infrastructure classes for `@RequestMapping` and `@ExceptionHandler`
3270+
methods detect Spring beans annotated with `@ControllerAdvice` and then apply their
3271+
methods at runtime. Global `@ExceptionHandler` methods (from a `@ControllerAdvice`) are
3272+
applied _after_ local ones (from the `@Controller`). By contrast, global `@ModelAttribute`
3273+
and `@InitBinder` methods are applied _before_ local ones.
3274+
3275+
By default, `@ControllerAdvice` methods apply to every request (that is, all controllers),
3276+
but you can narrow that down to a subset of controllers by using attributes on the
3277+
annotation, as the following example shows:
32773278

32783279
====
32793280
[source,java,indent=0]

0 commit comments

Comments
 (0)