@@ -5085,21 +5085,22 @@ without an `@Autowired` annotation.
5085
5085
====
5086
5086
Only one constructor of any given bean class may declare `@Autowired` with the `required`
5087
5087
attribute set to `true`, indicating _the_ constructor to autowire when used as a Spring
5088
- bean. Furthermore, if the `required` attribute is set to `true`, only a single
5089
- constructor may be annotated with `@Autowired`. If multiple _non-required_ constructors
5090
- declare the annotation, they will be considered as candidates for autowiring. The
5091
- constructor with the greatest number of dependencies that can be satisfied by matching
5088
+ bean. As a consequence, if the `required` attribute is left at its default value `true`,
5089
+ only a single constructor may be annotated with `@Autowired`. If multiple constructors
5090
+ declare the annotation, they will all have to declare `required=false` in order to be
5091
+ considered as candidates for autowiring (analogous to `autowire=constructor` in XML).
5092
+ The constructor with the greatest number of dependencies that can be satisfied by matching
5092
5093
beans in the Spring container will be chosen. If none of the candidates can be satisfied,
5093
5094
then a primary/default constructor (if present) will be used. If a class only declares a
5094
- single constructor to begin with, it will always be used, even if not annotated. An
5095
- annotated constructor does not have to be public.
5095
+ single constructor to begin with, it will always be used, even if not annotated. Note that
5096
+ an annotated constructor does not have to be public.
5096
5097
5097
5098
The `required` attribute of `@Autowired` is recommended over the deprecated `@Required`
5098
5099
annotation on setter methods. Setting the `required` attribute to `false` indicates that
5099
5100
the property is not required for autowiring purposes, and the property is ignored if it
5100
5101
cannot be autowired. `@Required`, on the other hand, is stronger in that it enforces the
5101
- property to be set by any means supported by the container, and if no value is defined, a
5102
- corresponding exception is raised.
5102
+ property to be set by any means supported by the container, and if no value is defined,
5103
+ a corresponding exception is raised.
5103
5104
====
5104
5105
5105
5106
Alternatively, you can express the non-required nature of a particular dependency
0 commit comments