|
69 | 69 | import org.springframework.util.StringUtils;
|
70 | 70 |
|
71 | 71 | /**
|
72 |
| - * {@link org.springframework.beans.factory.config.BeanPostProcessor} implementation |
73 |
| - * that autowires annotated fields, setter methods and arbitrary config methods. |
74 |
| - * Such members to be injected are detected through a Java 5 annotation: by default, |
75 |
| - * Spring's {@link Autowired @Autowired} and {@link Value @Value} annotations. |
| 72 | + * {@link org.springframework.beans.factory.config.BeanPostProcessor BeanPostProcessor} |
| 73 | + * implementation that autowires annotated fields, setter methods, and arbitrary |
| 74 | + * config methods. Such members to be injected are detected through annotations: |
| 75 | + * by default, Spring's {@link Autowired @Autowired} and {@link Value @Value} |
| 76 | + * annotations. |
76 | 77 | *
|
77 | 78 | * <p>Also supports JSR-330's {@link javax.inject.Inject @Inject} annotation,
|
78 | 79 | * if available, as a direct alternative to Spring's own {@code @Autowired}.
|
79 | 80 | *
|
80 |
| - * <p>Only one constructor (at max) of any given bean class may declare this annotation |
81 |
| - * with the 'required' parameter set to {@code true}, indicating <i>the</i> constructor |
82 |
| - * to autowire when used as a Spring bean. If multiple <i>non-required</i> constructors |
83 |
| - * declare the annotation, they will be considered as candidates for autowiring. |
84 |
| - * The constructor with the greatest number of dependencies that can be satisfied by |
85 |
| - * matching beans in the Spring container will be chosen. If none of the candidates |
86 |
| - * can be satisfied, then a primary/default constructor (if present) will be used. |
87 |
| - * If a class only declares a single constructor to begin with, it will always be used, |
88 |
| - * even if not annotated. An annotated constructor does not have to be public. |
| 81 | + * <h3>Autowired Constructors</h3> |
| 82 | + * <p>Only one constructor of any given bean class may declare this annotation with |
| 83 | + * the 'required' attribute set to {@code true}, indicating <i>the</i> constructor |
| 84 | + * to autowire when used as a Spring bean. Furthermore, if the 'required' attribute |
| 85 | + * is set to {@code true}, only a single constructor may be annotated with |
| 86 | + * {@code @Autowired}. If multiple <i>non-required</i> constructors declare the |
| 87 | + * annotation, they will be considered as candidates for autowiring. The constructor |
| 88 | + * with the greatest number of dependencies that can be satisfied by matching beans |
| 89 | + * in the Spring container will be chosen. If none of the candidates can be satisfied, |
| 90 | + * then a primary/default constructor (if present) will be used. If a class only |
| 91 | + * declares a single constructor to begin with, it will always be used, even if not |
| 92 | + * annotated. An annotated constructor does not have to be public. |
89 | 93 | *
|
| 94 | + * <h3>Autowired Fields</h3> |
90 | 95 | * <p>Fields are injected right after construction of a bean, before any
|
91 | 96 | * config methods are invoked. Such a config field does not have to be public.
|
92 | 97 | *
|
| 98 | + * <h3>Autowired Methods</h3> |
93 | 99 | * <p>Config methods may have an arbitrary name and any number of arguments; each of
|
94 | 100 | * those arguments will be autowired with a matching bean in the Spring container.
|
95 | 101 | * Bean property setter methods are effectively just a special case of such a
|
96 | 102 | * general config method. Config methods do not have to be public.
|
97 | 103 | *
|
98 |
| - * <p>Note: A default AutowiredAnnotationBeanPostProcessor will be registered |
| 104 | + * <h3>Annotation Config vs. XML Config</h3> |
| 105 | + * <p>A default {@code AutowiredAnnotationBeanPostProcessor} will be registered |
99 | 106 | * by the "context:annotation-config" and "context:component-scan" XML tags.
|
100 | 107 | * Remove or turn off the default annotation configuration there if you intend
|
101 |
| - * to specify a custom AutowiredAnnotationBeanPostProcessor bean definition. |
| 108 | + * to specify a custom {@code AutowiredAnnotationBeanPostProcessor} bean definition. |
| 109 | + * |
102 | 110 | * <p><b>NOTE:</b> Annotation injection will be performed <i>before</i> XML injection;
|
103 | 111 | * thus the latter configuration will override the former for properties wired through
|
104 | 112 | * both approaches.
|
105 | 113 | *
|
| 114 | + * <h3>{@literal @}Lookup Methods</h3> |
106 | 115 | * <p>In addition to regular injection points as discussed above, this post-processor
|
107 | 116 | * also handles Spring's {@link Lookup @Lookup} annotation which identifies lookup
|
108 | 117 | * methods to be replaced by the container at runtime. This is essentially a type-safe
|
109 |
| - * version of {@code getBean(Class, args)} and {@code getBean(String, args)}, |
| 118 | + * version of {@code getBean(Class, args)} and {@code getBean(String, args)}. |
110 | 119 | * See {@link Lookup @Lookup's javadoc} for details.
|
111 | 120 | *
|
112 | 121 | * @author Juergen Hoeller
|
113 | 122 | * @author Mark Fisher
|
114 | 123 | * @author Stephane Nicoll
|
115 | 124 | * @author Sebastien Deleuze
|
| 125 | + * @author Sam Brannen |
116 | 126 | * @since 2.5
|
117 | 127 | * @see #setAutowiredAnnotationType
|
118 | 128 | * @see Autowired
|
@@ -142,9 +152,10 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
142 | 152 |
|
143 | 153 |
|
144 | 154 | /**
|
145 |
| - * Create a new AutowiredAnnotationBeanPostProcessor |
146 |
| - * for Spring's standard {@link Autowired} annotation. |
147 |
| - * <p>Also supports JSR-330's {@link javax.inject.Inject} annotation, if available. |
| 155 | + * Create a new {@code AutowiredAnnotationBeanPostProcessor} for Spring's |
| 156 | + * standard {@link Autowired @Autowired} annotation. |
| 157 | + * <p>Also supports JSR-330's {@link javax.inject.Inject @Inject} annotation, |
| 158 | + * if available. |
148 | 159 | */
|
149 | 160 | @SuppressWarnings("unchecked")
|
150 | 161 | public AutowiredAnnotationBeanPostProcessor() {
|
|
0 commit comments