Skip to content

can't @autowire collections [SPR-5038] #9713

Closed

Activity

  1. spring-projects-issues commented on Jul 25, 2008

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Collections and arrays are handled specifically for autowiring purposes: The container is building collections of beans, or maps of bean names to bean objects there. In other words, it is autowiring the elements of those collections (i.e. a couple of matching bean instances collected), not the collections themselves (i.e. not the collection itself as a bean).

    We'll revisit this for Spring 3.0, since I agree that collection objects as beans are common as well and should be supported through @Autowired too.

    Juergen

  2. spring-projects-issues commented on Jul 25, 2008

    @spring-projects-issues
    CollaboratorAuthor

    Rusty Wright commented

    Thanks. I found the note in the manual about @Resource and that fixes it. At this point I'd suggest peppering the docs with references to @Resource wherever it discusses autowiring things or about collections. E.g., "note: if you're trying to auto wire a collection with annotations you'll need to use @Resource instead of @Autowired".

  3. spring-projects-issues commented on Feb 3, 2009

    @spring-projects-issues
    CollaboratorAuthor

    jason bayk commented

    I am using Spring 3 M1 and encountered the same issue. I am trying to auto wire a BlockingQueue instance and getting the same "No matching bean of type ... found for dependency ... collection"
    Also did not quite get the last comment about the workaround using @Resource annotation. This annotation does not seem to exist at all.

  4. spring-projects-issues commented on Feb 3, 2009

    @spring-projects-issues
    CollaboratorAuthor

    Rusty Wright commented

    Ok

  5. spring-projects-issues commented on Feb 3, 2009

    @spring-projects-issues
    CollaboratorAuthor

    Rusty Wright commented

    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>annotations-api</artifactId>
        <version>6.0.16</version>
    </dependency>
    

    That's from my maven pom.xml.

    In my java code I have

    import javax.annotation.Resource;

    and then I can use @Resource

  6. spring-projects-issues commented on Feb 3, 2009

    @spring-projects-issues
    CollaboratorAuthor

    Rusty Wright commented

    And if you're using tomcat you need tomcat 6; 5 and previous won't work. I think this annotation is part of the newer servlet spec, or something newer.

  7. spring-projects-issues commented on Feb 12, 2009

    @spring-projects-issues
    CollaboratorAuthor

    jason bayk commented

    Thanks Rusty. Unfortunately my application is not running in a web container, so I guess I could not really use the workaround. For now I will just have to wait for M3.

  8. spring-projects-issues commented on Feb 12, 2009

    @spring-projects-issues
    CollaboratorAuthor

    Rusty Wright commented

    Perhaps there's an implementation of that annotations JSR that you can use outside of a servlet container. On my windows machine at home I have a pdf that documents the JSR, but I don't remember where I downloaded it from. Try looking in the spring reference guide for the JSR number and doing a google search on it. It seems to me (in my naive optimistic world) that you ought to be able to use those annotations outside of a web container.

  9. spring-projects-issues commented on Feb 12, 2009

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Hi guys,

    FYI: @Resource is part of JSR-250, and you can certainly use it in Java SE 5 simply by making the appropriate JAR available on the classpath. Note that the annotations defined in JSR-250 are available by default with Java EE 5+ and Java SE 6+.

    If you're looking for the JAR, you can find it, for example, from...

    Maven Repository: http://mvnrepository.com/artifact/javax.annotation/jsr250-api

    SpringSource Enterprise Bundle Repository: http://www.springsource.com/repository/app/bundle/version/detail?name=com.springsource.javax.annotation&version=1.0.0&searchType=bundlesBySymbolicName&searchQuery=javax.annotation

    Regards,

    Sam

  10. spring-projects-issues commented on Feb 13, 2009

    @spring-projects-issues
    CollaboratorAuthor

    jason bayk commented

    Thanks. That worked. I did not realize there is an alternative to the spring-specific @Autowired annotation.
    Basically it mean that my auto-wired classes can be completely free of spring imports.

  11. spring-projects-issues commented on Mar 26, 2009

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    We'll leave this as-is for the time being, since there is not only @Resource as a solution but also @Value in Spring 3.0 now. @Value allows for referring to specific named beans using a #{...} expression, and even dereferencing them: e.g. calling a getter on some other bean which in turn results in a Collection or Map.

    We may revisit this in the future but for the time being other enhancements have higher priority.

    Juergen

  12. added
    status: declined
    type: enhancement
    in: core
    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

in: corestatus: declinedtype: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions