我尝试用SpringJUnit4ClassRunner注入juni测试运行这个bean:
<util:list id="MyList" value-type="java.lang.String">
<value>val1</value>
<value>val2</value>
<value>val3</value>
</util:list>
在测试用例MyTestCase中: @Resource(mappedName =“MyList”) @Qualifier( “MYLIST”) private List myList;
但总是收到异常: org.springframework.beans.factory.BeanCreationException:
Error creating bean MyTestCase
...................
org.springframework.beans.factory.NoSuchBeanDefinitionException: 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: {@javax.annotation.Resource(shareable=true,
mappedName=, description=, name=,
type=class java.lang.Object,
authenticationType=CONTAINER),
org.springframework.beans.factory.annotation.Qualifier(value=MyList)}
可能是什么原因? 感谢。
答案 0 :(得分:3)
@Resource(name="MyList")
private List<String> list;
如果不起作用,请设置bean的name
。如果您使用@Qualifier
<qualifier>
注释会起作用