title: Spring @Autowired bean not found, No qualifying bean of type [...] found
body: <p>I get the following exception when trying to start my application context in a TestNG-Test:</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'albumService': Injection of autowired dependencies failed; nested exception is
   org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.yoon.archive.dao.AlbumDao net.yoon.archive.service.AlbumService.albumDa
  o; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [net.yoon.archive.dao.AlbumDao] found for dependency: exp
  ected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
      at [... Framework code ...]
  
  Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private net.yoon.archive.dao.AlbumDao net.yoon.archive.service.AlbumService.albumDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [net.yoon.archive.dao.AlbumDao] 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 [...]
  Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [net.yoon.archive.dao.AlbumDao] 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 [...]
  </code></pre>
  
  <p>As far as my understanding of building a spring application context goes I should be doing it correctly, similar questions of this nature have sadly also not given me any answers that solved the error. </p>
  
  <p>Sorry for the wall of code below, but I felt it could all be relevant.</p>
  
  <p>The bean that can't be autowired:</p>
  
  <pre><code>package net.yoon.archive.dao;
  
  import net.yoon.archive.domain.music.Album;
  
  import org.springframework.stereotype.Repository;
  import org.springframework.transaction.annotation.Transactional;
  
  @Repository
  @Transactional
  public class AlbumDao extends AbstractHibernateDao&lt;Album&gt; {
  
  }
  </code></pre>
  
  <p>The bean I'm trying to autowire it in:</p>
  
  <pre><code>package net.yoon.archive.service;
  
  import net.yoon.archive.dao.AbstractHibernateDao;
  import net.yoon.archive.dao.AlbumDao;
  import net.yoon.archive.domain.music.Album;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  @Service
  public class AlbumService extends AbstractDaoService&lt;Album&gt; {
  
      @Autowired
      private AlbumDao albumDao;
  
      @Override
      protected AbstractHibernateDao&lt;Album&gt; getDao() {
          return albumDao;
      }
  }
  </code></pre>
  
  <p>The test class that's creating the application context:</p>
  
  <pre><code>package net.yoon.archive.service;
  
  import net.yoon.archive.TestGroups;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.test.context.ContextConfiguration;
  import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
  import org.testng.Assert;
  import org.testng.annotations.Test;
  
  @Test(groups = { TestGroups.SERVICE_TEST })
  @ContextConfiguration({ "classpath:applicationContext.xml" })
  public class NameServiceTest extends AbstractTestNGSpringContextTests {
  
      @Autowired
      private NameService nameService;
  
      public void testSetup() {
          Assert.assertNotNull(nameService);
      }
  }
  </code></pre>
  
  <p>My applicationContext.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:p="http://www.springframework.org/schema/p"
      xsi:schemaLocation="
          http://www.springframework.org/schema/tx 
          http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/beans    
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;tx:annotation-driven /&gt;
  
      &lt;context:component-scan base-package="net.yoon.archive" /&gt;
  
      &lt;bean id="transactionManager"
          class="org.springframework.orm.hibernate4.HibernateTransactionManager"
          p:sessionFactory-ref="sessionFactory"&gt;
      &lt;/bean&gt;
  
      &lt;bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"&gt;
          [...]
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          [...]
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>