Description
Fabrizio Cucci opened SPR-14332 and commented
Hi spring staff,
I'm writing to signal a documentation improvement related to this Stack Overflow question.
I'm referring to this section and specifically the following statement:
??As a specific consequence of this semantic difference, beans that are themselves defined as a collection or map type cannot be injected through @Autowired
, because type matching is not properly applicable to them. Use @Resource
for such beans, referring to the specific collection or map bean by unique name.??
There are a couple of implicit, but important, consequences of the previous statement:
- since
@Autowired
cannot be used to inject beans that are themselves defined as a collection or map and@Resource
is not applicable to constructors, constructor injection of those beans is currently not possible; - what mentioned before applies also to arrays, besides collections and maps.
Whether this is a limitation or a design choice is debatable but still, for the time being, I think the documentation should be more explicit about those points.
Thanks,
Fabrizio
Affects: 4.3 RC2
Reference URL: http://stackoverflow.com/questions/37622337/constructor-injection-and-arrays-with-spring
Issue Links:
- Allow for normal bean wiring semantics for types assignable to Map [SPR-7915] #12570 Allow for normal bean wiring semantics for types assignable to Map
- @Autowired does not work for target bean of type Collection [SPR-12180] #16794
@Autowired
does not work for target bean of type Collection