Skip to content

Commit 817f689

Browse files
committed
Improve Javadoc for AutowiredAnnotationBeanPostProcessor
See gh-23263
1 parent d2a7d9f commit 817f689

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,50 +69,60 @@
6969
import org.springframework.util.StringUtils;
7070

7171
/**
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.
7677
*
7778
* <p>Also supports JSR-330's {@link javax.inject.Inject @Inject} annotation,
7879
* if available, as a direct alternative to Spring's own {@code @Autowired}.
7980
*
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.
8993
*
94+
* <h3>Autowired Fields</h3>
9095
* <p>Fields are injected right after construction of a bean, before any
9196
* config methods are invoked. Such a config field does not have to be public.
9297
*
98+
* <h3>Autowired Methods</h3>
9399
* <p>Config methods may have an arbitrary name and any number of arguments; each of
94100
* those arguments will be autowired with a matching bean in the Spring container.
95101
* Bean property setter methods are effectively just a special case of such a
96102
* general config method. Config methods do not have to be public.
97103
*
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
99106
* by the "context:annotation-config" and "context:component-scan" XML tags.
100107
* 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+
*
102110
* <p><b>NOTE:</b> Annotation injection will be performed <i>before</i> XML injection;
103111
* thus the latter configuration will override the former for properties wired through
104112
* both approaches.
105113
*
114+
* <h3>{@literal @}Lookup Methods</h3>
106115
* <p>In addition to regular injection points as discussed above, this post-processor
107116
* also handles Spring's {@link Lookup @Lookup} annotation which identifies lookup
108117
* 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)}.
110119
* See {@link Lookup @Lookup's javadoc} for details.
111120
*
112121
* @author Juergen Hoeller
113122
* @author Mark Fisher
114123
* @author Stephane Nicoll
115124
* @author Sebastien Deleuze
125+
* @author Sam Brannen
116126
* @since 2.5
117127
* @see #setAutowiredAnnotationType
118128
* @see Autowired
@@ -142,9 +152,10 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
142152

143153

144154
/**
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.
148159
*/
149160
@SuppressWarnings("unchecked")
150161
public AutowiredAnnotationBeanPostProcessor() {

0 commit comments

Comments
 (0)