You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement
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.
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".
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.
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.
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.
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.
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...
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.
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.
in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement
Activity
spring-projects-issues commentedon Jul 25, 2008
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
@Autowiredtoo.Juergen
spring-projects-issues commentedon Jul 25, 2008
Rusty Wright commented
Thanks. I found the note in the manual about
@Resourceand that fixes it. At this point I'd suggest peppering the docs with references to@Resourcewherever 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@Resourceinstead of@Autowired".spring-projects-issues commentedon Feb 3, 2009
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
@Resourceannotation. This annotation does not seem to exist at all.spring-projects-issues commentedon Feb 3, 2009
Rusty Wright commented
Ok
spring-projects-issues commentedon Feb 3, 2009
Rusty Wright commented
That's from my maven pom.xml.
In my java code I have
import javax.annotation.Resource;
and then I can use
@Resourcespring-projects-issues commentedon Feb 3, 2009
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.
spring-projects-issues commentedon Feb 12, 2009
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.
spring-projects-issues commentedon Feb 12, 2009
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.
spring-projects-issues commentedon Feb 12, 2009
Sam Brannen commented
Hi guys,
FYI:
@Resourceis 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
spring-projects-issues commentedon Feb 13, 2009
jason bayk commented
Thanks. That worked. I did not realize there is an alternative to the spring-specific
@Autowiredannotation.Basically it mean that my auto-wired classes can be completely free of spring imports.
spring-projects-issues commentedon Mar 26, 2009
Juergen Hoeller commented
We'll leave this as-is for the time being, since there is not only
@Resourceas a solution but also@Valuein Spring 3.0 now.@Valueallows 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