title: Spring web application, Injection of autowired dependencies fail
body: <p>I am setting up a simple Hello World web application with Spring and Maven.
  Somehow, I keep getting a BeanCreationException when trying to autowire my test bean.</p>
  
  <p>Hello Bean:</p>
  
  <pre><code>package de.dijon.test;
  
  public class HelloBean {
  private String name;
  
  public void setName(String name) {
      this.name = name;
  }
  
  public String getHello() {
      return ("Hello " + name);
  }
  }
  </code></pre>
  
  <p>web.xml:</p>
  
  <pre><code>    &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;/WEB-INF/application-context.xml&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  </code></pre>
  
  <p>application-context.xml:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;
  
  &lt;bean id="helloBean" class="de.dijon.test.HelloBean"
      autowire="byType"&gt;
      &lt;property name="name" value="Dijon" /&gt;
  &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>My test class:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(locations = { "classpath*:/application-context.xml" })
  public class AppTest extends TestCase {
  
  @Autowired
  private HelloBean obj;
  
  @Test
  public void test() {
      assertNotNull(obj.getHello());
  }
  }
  </code></pre>
  
  <p>Errormessage:</p>
  
  <pre><code>Dec 23, 2013 1:31:59 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
  INFO: Refreshing org.springframework.context.support.GenericApplicationContext@2b275d39: startup date [Mon Dec 23 13:31:59 CET 2013]; root of context hierarchy
  Dec 23, 2013 1:31:59 PM org.springframework.test.context.TestContextManager prepareTestInstance
  SEVERE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@371bed71] to prepare test instance [null(de.dijon.test.test.AppTest)]
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'de.dijon.test.test.AppTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.dijon.test.HelloBean de.dijon.test.test.AppTest.obj; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [de.dijon.test.HelloBean] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:384)
      at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)
      at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
      at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:326)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:212)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:289)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:291)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:232)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:175)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private de.dijon.test.HelloBean de.dijon.test.test.AppTest.obj; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [de.dijon.test.HelloBean] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508)
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
      ... 26 more
  Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [de.dijon.test.HelloBean] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1100)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855)
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
      ... 28 more
  Dec 23, 2013 1:31:59 PM org.springframework.context.support.AbstractApplicationContext doClose
  INFO: Closing org.springframework.context.support.GenericApplicationContext@2b275d39: startup date [Mon Dec 23 13:31:59 CET 2013]; root of context hierarchy
  </code></pre>
  
  <p>Maybe somebody could help me, and tell me, what the reason for not properly auto wiring is. I tried to find this out for the last couple of hours and don't have any ideas.
  Thank you very much!</p>