Skip to content

Doc: Constructor injection of arrays and collections [SPR-14332] #18904

Closed

Description

@spring-projects-issues

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:

  1. 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;
  2. 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:

Activity

  1. spring-projects-issues commented on Jun 6, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Hopefully to the better, @Autowired can actually match collection/map and array types as of 4.3! So that documentation section actually needs to be updated towards 4.3's capabilities...

  2. added this to the 4.3 GA milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: documentation

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions