简体   繁体   中英

How to autowire util:list?

I try to inject into juni test run with SpringJUnit4ClassRunner this bean:

<util:list id="MyList" value-type="java.lang.String">
    <value>val1</value>
    <value>val2</value>
    <value>val3</value>
</util:list>

In test case MyTestCase: @Resource (mappedName="MyList") @Qualifier("MyList") private List myList;

But always receive exception: 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)}

What can be the reason? Thanks.

@Resource(name="MyList")
private List<String> list;

If it doesn't work, set the name of the bean. The @Qualifier annotation works if you've used <qualifier>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM