Skip to content

Commit e54eb56

Browse files
committed
Revised javadoc for up-to-date constructor autowiring semantics
Issue: SPR-17299 (cherry picked from commit 333e327)
1 parent f5e6c70 commit e54eb56

File tree

3 files changed

+45
-42
lines changed

3 files changed

+45
-42
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/Aware.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,21 +17,19 @@
1717
package org.springframework.beans.factory;
1818

1919
/**
20-
* Marker superinterface indicating that a bean is eligible to be
21-
* notified by the Spring container of a particular framework object
22-
* through a callback-style method. Actual method signature is
23-
* determined by individual subinterfaces, but should typically
24-
* consist of just one void-returning method that accepts a single
25-
* argument.
20+
* A marker superinterface indicating that a bean is eligible to be notified by the
21+
* Spring container of a particular framework object through a callback-style method.
22+
* The actual method signature is determined by individual subinterfaces but should
23+
* typically consist of just one void-returning method that accepts a single argument.
2624
*
27-
* <p>Note that merely implementing {@link Aware} provides no default
28-
* functionality. Rather, processing must be done explicitly, for example
29-
* in a {@link org.springframework.beans.factory.config.BeanPostProcessor BeanPostProcessor}.
25+
* <p>Note that merely implementing {@link Aware} provides no default functionality.
26+
* Rather, processing must be done explicitly, for example in a
27+
* {@link org.springframework.beans.factory.config.BeanPostProcessor}.
3028
* Refer to {@link org.springframework.context.support.ApplicationContextAwareProcessor}
31-
* and {@link org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory}
32-
* for examples of processing {@code *Aware} interface callbacks.
29+
* for an example of processing specific {@code *Aware} interface callbacks.
3330
*
3431
* @author Chris Beams
32+
* @author Juergen Hoeller
3533
* @since 3.1
3634
*/
3735
public interface Aware {

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,15 +23,22 @@
2323
import java.lang.annotation.Target;
2424

2525
/**
26-
* Marks a constructor, field, setter method or config method as to be autowired
27-
* by Spring's dependency injection facilities.
26+
* Marks a constructor, field, setter method or config method as to be autowired by
27+
* Spring's dependency injection facilities. This is an alternative to the JSR-330
28+
* {@link javax.inject.Inject} annotation, adding required-vs-optional semantics.
2829
*
29-
* <p>Only one constructor (at max) of any given bean class may carry this annotation,
30-
* indicating the constructor to autowire when used as a Spring bean. Such a
31-
* constructor does not have to be public.
30+
* <p>Only one constructor (at max) of any given bean class may declare this annotation
31+
* with the 'required' parameter set to {@code true}, indicating <i>the</i> constructor
32+
* to autowire when used as a Spring bean. If multiple <i>non-required</i> constructors
33+
* declare the annotation, they will be considered as candidates for autowiring.
34+
* The constructor with the greatest number of dependencies that can be satisfied by
35+
* matching beans in the Spring container will be chosen. If none of the candidates
36+
* can be satisfied, then a primary/default constructor (if present) will be used.
37+
* If a class only declares a single constructor to begin with, it will always be used,
38+
* even if not annotated. An annotated constructor does not have to be public.
3239
*
33-
* <p>Fields are injected right after construction of a bean, before any config
34-
* methods are invoked. Such a config field does not have to be public.
40+
* <p>Fields are injected right after construction of a bean, before any config methods
41+
* are invoked. Such a config field does not have to be public.
3542
*
3643
* <p>Config methods may have an arbitrary name and any number of arguments; each of
3744
* those arguments will be autowired with a matching bean in the Spring container.

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

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@
7474
* <p>Also supports JSR-330's {@link javax.inject.Inject @Inject} annotation,
7575
* if available, as a direct alternative to Spring's own {@code @Autowired}.
7676
*
77-
* <p>Only one constructor (at max) of any given bean class may carry this
78-
* annotation with the 'required' parameter set to {@code true},
79-
* indicating <i>the</i> constructor to autowire when used as a Spring bean.
80-
* If multiple <i>non-required</i> constructors carry the annotation, they
81-
* will be considered as candidates for autowiring. The constructor with
82-
* the greatest number of dependencies that can be satisfied by matching
83-
* beans in the Spring container will be chosen. If none of the candidates
84-
* can be satisfied, then a default constructor (if present) will be used.
85-
* An annotated constructor does not have to be public.
77+
* <p>Only one constructor (at max) of any given bean class may declare this annotation
78+
* with the 'required' parameter set to {@code true}, indicating <i>the</i> constructor
79+
* to autowire when used as a Spring bean. If multiple <i>non-required</i> constructors
80+
* declare the annotation, they will be considered as candidates for autowiring.
81+
* The constructor with the greatest number of dependencies that can be satisfied by
82+
* matching beans in the Spring container will be chosen. If none of the candidates
83+
* can be satisfied, then a primary/default constructor (if present) will be used.
84+
* If a class only declares a single constructor to begin with, it will always be used,
85+
* even if not annotated. An annotated constructor does not have to be public.
8686
*
8787
* <p>Fields are injected right after construction of a bean, before any
8888
* config methods are invoked. Such a config field does not have to be public.
@@ -161,11 +161,11 @@ public AutowiredAnnotationBeanPostProcessor() {
161161
/**
162162
* Set the 'autowired' annotation type, to be used on constructors, fields,
163163
* setter methods and arbitrary config methods.
164-
* <p>The default autowired annotation type is the Spring-provided
165-
* {@link Autowired} annotation, as well as {@link Value}.
164+
* <p>The default autowired annotation type is the Spring-provided {@link Autowired}
165+
* annotation, as well as {@link Value}.
166166
* <p>This setter property exists so that developers can provide their own
167-
* (non-Spring-specific) annotation type to indicate that a member is
168-
* supposed to be autowired.
167+
* (non-Spring-specific) annotation type to indicate that a member is supposed
168+
* to be autowired.
169169
*/
170170
public void setAutowiredAnnotationType(Class<? extends Annotation> autowiredAnnotationType) {
171171
Assert.notNull(autowiredAnnotationType, "'autowiredAnnotationType' must not be null");
@@ -176,11 +176,11 @@ public void setAutowiredAnnotationType(Class<? extends Annotation> autowiredAnno
176176
/**
177177
* Set the 'autowired' annotation types, to be used on constructors, fields,
178178
* setter methods and arbitrary config methods.
179-
* <p>The default autowired annotation type is the Spring-provided
180-
* {@link Autowired} annotation, as well as {@link Value}.
179+
* <p>The default autowired annotation type is the Spring-provided {@link Autowired}
180+
* annotation, as well as {@link Value}.
181181
* <p>This setter property exists so that developers can provide their own
182-
* (non-Spring-specific) annotation types to indicate that a member is
183-
* supposed to be autowired.
182+
* (non-Spring-specific) annotation types to indicate that a member is supposed
183+
* to be autowired.
184184
*/
185185
public void setAutowiredAnnotationTypes(Set<Class<? extends Annotation>> autowiredAnnotationTypes) {
186186
Assert.notEmpty(autowiredAnnotationTypes, "'autowiredAnnotationTypes' must not be empty");
@@ -189,8 +189,7 @@ public void setAutowiredAnnotationTypes(Set<Class<? extends Annotation>> autowir
189189
}
190190

191191
/**
192-
* Set the name of a parameter of the annotation that specifies
193-
* whether it is required.
192+
* Set the name of a parameter of the annotation that specifies whether it is required.
194193
* @see #setRequiredParameterValue(boolean)
195194
*/
196195
public void setRequiredParameterName(String requiredParameterName) {
@@ -199,9 +198,8 @@ public void setRequiredParameterName(String requiredParameterName) {
199198

200199
/**
201200
* Set the boolean value that marks a dependency as required
202-
* <p>For example if using 'required=true' (the default),
203-
* this value should be {@code true}; but if using
204-
* 'optional=false', this value should be {@code false}.
201+
* <p>For example if using 'required=true' (the default), this value should be
202+
* {@code true}; but if using 'optional=false', this value should be {@code false}.
205203
* @see #setRequiredParameterName(String)
206204
*/
207205
public void setRequiredParameterValue(boolean requiredParameterValue) {

0 commit comments

Comments
 (0)