我想使用Spring,并遇到麻烦使用它的情况。 我有以下代码:使用嵌套的bean时,依赖注入与Spring不工作
<util:map id="someMap" value-type="java.util.Set">
<entry key="a" value-ref="setA"/>
<entry key="b" value-ref="setB"/>
</util:map>
<util:set id="setA">
<value>A</value>
</util:set>
<util:set id="setB">
<value>B</value>
</util:set>
与下面的Java代码(使用@Qualifier得到 “someMap”):
package a.b.c;
public class SomeClass {
private final Map<String, Set<String>> someMap;
@Autowired
public SomeClass(@Qualifier("someMap") final Map<String, Set<String>> someMap) {
this.someMap = someMap;
}
}
和它给我下面的错误:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'a.b.c.SomeClass': Unsatisfied dependency expressed through constructor argument with index 2 of type [java.util.Map]: : No matching bean of type [java.util.Set] found for dependency [map with value type java.util.Set]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:{@org.springframework.beans.factory.annotation.Qualifier(value=someMap)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [java.util.Set] found for dependency [map with value type java.util.Set]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=someMap)}
看起来它很难找到Set,但我不知道它为什么会发生。你会如何解决这个问题?
是否使用spring 4.3或更高版本version.lower春天版本,你不能autowire集合 – Assen