Document default constructor as fallback for non-@Autowired constructors
Prior to this commit, it was unclear in the documentation that a default constructor will be used by default for autowiring if multiple constructors are present and none of them is annotated with @Autowired. This commit improves the documentation in this regard. Closes gh-24838
This commit is contained in:
@@ -36,9 +36,11 @@ import java.lang.annotation.Target;
|
||||
* annotation, they will be considered as candidates for autowiring. The constructor
|
||||
* with the greatest number of dependencies that can be satisfied by matching beans
|
||||
* in the Spring container will be chosen. If none of the candidates can be satisfied,
|
||||
* then a primary/default constructor (if present) will be used. If a class only
|
||||
* declares a single constructor to begin with, it will always be used, even if not
|
||||
* annotated. An annotated constructor does not have to be public.
|
||||
* then a primary/default constructor (if present) will be used. Similarly, if a
|
||||
* class declares multiple constructors but none of them is annotated with
|
||||
* {@code @Autowired}, then a primary/default constructor (if present) will be used.
|
||||
* If a class only declares a single constructor to begin with, it will always be used,
|
||||
* even if not annotated. An annotated constructor does not have to be public.
|
||||
*
|
||||
* <h3>Autowired Fields</h3>
|
||||
* <p>Fields are injected right after construction of a bean, before any config methods
|
||||
|
||||
Reference in New Issue
Block a user