Skip to content

Commit e7561b1

Browse files
committed
Updated @Autowired documentation in terms of collection/map/array matching
Issue: SPR-14332
1 parent 998b83c commit e7561b1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/asciidoc/core-beans.adoc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4593,15 +4593,16 @@ If you intend to express annotation-driven injection by name, do not primarily u
45934593
semantically defined to identify a specific target component by its unique name, with
45944594
the declared type being irrelevant for the matching process.
45954595
4596-
As a specific consequence of this semantic difference, beans that are themselves defined
4597-
as a collection or map type cannot be injected through `@Autowired`, because type
4598-
matching is not properly applicable to them. Use `@Resource` for such beans, referring
4599-
to the specific collection or map bean by unique name.
4596+
For beans that are themselves defined as a collection/map or array type, `@Resource`
4597+
is a fine solution, referring to the specific collection or array bean by unique name.
4598+
That said, as of 4.3, collection/map and array types can be matched through Spring's
4599+
`@Autowired` type matching algorithm as well, as long as the element type information
4600+
is preserved in `@Bean` return type signatures or collection inheritance hierarchies.
46004601
46014602
`@Autowired` applies to fields, constructors, and multi-argument methods, allowing for
46024603
narrowing through qualifier annotations at the parameter level. By contrast, `@Resource`
4603-
is supported only for fields and bean property setter methods with a single argument. As
4604-
a consequence, stick with qualifiers if your injection target is a constructor or a
4604+
is supported only for fields and bean property setter methods with a single argument.
4605+
As a consequence, stick with qualifiers if your injection target is a constructor or a
46054606
multi-argument method.
46064607
====
46074608

0 commit comments

Comments
 (0)