|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2015 the original author or authors. |
| 2 | + * Copyright 2002-2017 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
26 | 26 | import org.springframework.core.annotation.AliasFor;
|
27 | 27 | import org.springframework.stereotype.Component;
|
28 | 28 |
|
| 29 | + |
29 | 30 | /**
|
30 |
| - * Indicates the annotated class assists a "Controller". |
31 |
| - * |
32 |
| - * <p>Serves as a specialization of {@link Component @Component}, allowing for |
33 |
| - * implementation classes to be autodetected through classpath scanning. |
34 |
| - * |
35 |
| - * <p>It is typically used to define {@link ExceptionHandler @ExceptionHandler}, |
36 |
| - * {@link InitBinder @InitBinder}, and {@link ModelAttribute @ModelAttribute} |
37 |
| - * methods that apply to all {@link RequestMapping @RequestMapping} methods. |
38 |
| - * |
39 |
| - * <p>One of {@link #annotations()}, {@link #basePackageClasses()}, |
40 |
| - * {@link #basePackages()} or its alias {@link #value()} |
41 |
| - * may be specified to define specific subsets of Controllers |
42 |
| - * to assist. When multiple selectors are applied, OR logic is applied - |
43 |
| - * meaning selected Controllers should match at least one selector. |
| 31 | + * Specialization of {@link Component @Component} for classes that declare |
| 32 | + * {@link ExceptionHandler @ExceptionHandler}, {@link InitBinder @InitBinder}, or |
| 33 | + * {@link ModelAttribute @ModelAttribute} methods to be shared across |
| 34 | + * multiple {@code @Controller} classes. |
44 | 35 | *
|
45 |
| - * <p>The default behavior (i.e. if used without any selector), |
46 |
| - * the {@code @ControllerAdvice} annotated class will |
47 |
| - * assist all known Controllers. |
| 36 | + * <p>Classes with {@code @ControllerAdvice} can be declared explicitly as Spring |
| 37 | + * beans or auto-detected via classpath scanning. All such beans are sorted via |
| 38 | + * {@link org.springframework.core.annotation.AnnotationAwareOrderComparator |
| 39 | + * AnnotationAwareOrderComparator}, i.e. based on |
| 40 | + * {@link org.springframework.core.annotation.Order @Order} and |
| 41 | + * {@link org.springframework.core.Ordered Ordered}, and applied in that order |
| 42 | + * at runtime. For handling exceptions the first {@code @ExceptionHandler} to |
| 43 | + * match the exception is used. For model attributes and {@code InitBinder} |
| 44 | + * initialization, {@code @ModelAttribute} and {@code @InitBinder} methods will |
| 45 | + * also follow {@code @ControllerAdvice} order. |
48 | 46 | *
|
49 |
| - * <p>Note that those checks are done at runtime, so adding many attributes and using |
50 |
| - * multiple strategies may have negative impacts (complexity, performance). |
| 47 | + * <p>By default the methods in an {@code @ControllerAdvice} apply globally to |
| 48 | + * all Controllers. Use selectors {@link #annotations()}, |
| 49 | + * {@link #basePackageClasses()}, and {@link #basePackages()} (or its alias |
| 50 | + * {@link #value()}) to define a more narrow subset of targeted Controllers. |
| 51 | + * If multiple selectors are declared, OR logic is applied, meaning selected |
| 52 | + * Controllers should match at least one selector. Note that selector checks |
| 53 | + * are performed at runtime and so adding many selectors may negatively impact |
| 54 | + * performance and add complexity. |
51 | 55 | *
|
52 | 56 | * @author Rossen Stoyanchev
|
53 | 57 | * @author Brian Clozel
|
|
0 commit comments