I have what seems to be a simple problem, as stated in the title. Here is the kind of class I have :
public class Foo {
@Autowired
public Foo(@Qualifier("bar") Set<String> bar) {
// ...
}
}
Which I try to run with the following spring context :
<context:annotation-config />
<util:set id="bar">
<value>tata</value>
<value>titi</value>
<value>toto</value>
</util:set>
<bean id="foo" class="Foo" />
This fails to run with :
No matching bean of type
[java.lang.String] found for
dependency [collection of
java.lang.String]: expected at least 1
bean which qualifies as autowire
candidate for this dependency.
Dependency annotations:
{@org.springframework.beans.factory.annotation.Qualifier(value=bar)}
Note that if I add other parameters to my constructor, it works fine. If I use setter injection, it works fine. I’m sure I miss something obvious … do you know what ?
Autowiring collections is not possible using the
@Autowiredannotation. An autowired collection means “to provide all beans of a particular type”. Using the JSR-250@Resourceannotation, you can declare that you want a resource injected by its name, not its type. Or you inject the dependency explicitly.See the Spring documentation for more details.