Note that there are some explanatory texts on larger screens.

plurals
  1. POAuto-wiring a List using util schema gives NoSuchBeanDefinitionException
    text
    copied!<p>I have a bean that i want to inject with a named list using Spring util namespace <code>&lt;util:list id="myList"&gt;</code> but Spring is looking for a collection of beans of type String instead. My broken test is:</p> <pre><code>@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration public class ListInjectionTest { @Autowired @Qualifier("myList") private List&lt;String&gt; stringList; @Test public void testNotNull() { TestCase.assertNotNull("stringList not null", stringList); } } </code></pre> <p>My context is:</p> <pre><code>&lt;beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"&gt; &lt;util:list id="myList"&gt; &lt;value&gt;foo&lt;/value&gt; &lt;value&gt;bar&lt;/value&gt; &lt;/util:list&gt; &lt;/beans&gt; </code></pre> <p>But I get </p> <pre><code>Caused by: 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: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=myList)} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:726) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:571) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:412) </code></pre> <p>Which puzzles me rather as I figured this would be the way it was expected to work.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload