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:
Sam Brannen
2020-04-07 14:35:40 +02:00
parent a5498ba2ad
commit 6c26765985
2 changed files with 19 additions and 11 deletions

View File

@@ -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