@@ -4538,15 +4538,19 @@ e.g. declared as a single public constructor without an `@Autowired` annotation.
4538
4538
4539
4539
[NOTE]
4540
4540
====
4541
- Only one annotated constructor per class can be marked as required, but multiple
4542
- non-required constructors can be annotated. In that case, each is considered among
4543
- the candidates and Spring uses the greediest constructor whose dependencies can be
4544
- satisfied -- that is, the constructor that has the largest number of arguments.
4545
- The constructor resolution algorithm is the same as for non-annotated classes with
4546
- overloaded constructors, just narrowing the candidates to annotated constructors.
4547
-
4548
- The 'required' attribute of `@Autowired` is recommended over the `@Required` annotation
4549
- on setter methods. The 'required' attribute indicates that the property is not required
4541
+ Only one constructor of any given bean class may declare `@Autowired` with the `required`
4542
+ attribute set to `true`, indicating _the_ constructor to autowire when used as a Spring
4543
+ bean. Furthermore, if the `required` attribute is set to `true`, only a single
4544
+ constructor may be annotated with `@Autowired`. If multiple _non-required_ constructors
4545
+ declare the annotation, they will be considered as candidates for autowiring. The
4546
+ constructor with the greatest number of dependencies that can be satisfied by matching
4547
+ beans in the Spring container will be chosen. If none of the candidates can be satisfied,
4548
+ then a primary/default constructor (if present) will be used. If a class only declares a
4549
+ single constructor to begin with, it will always be used, even if not annotated. An
4550
+ annotated constructor does not have to be public.
4551
+
4552
+ The `required` attribute of `@Autowired` is recommended over the `@Required` annotation
4553
+ on setter methods. The `required` attribute indicates that the property is not required
4550
4554
for autowiring purposes. The property is ignored if it cannot be autowired. `@Required`,
4551
4555
on the other hand, is stronger in that it enforces the property to be set by any means
4552
4556
supported by the container. If no value is defined, a corresponding exception is raised.
0 commit comments