title: Spring can not set dao bean in controller
body: <p>I'm trying to inject a dao-bean in my controller from spring MVC. I'm using the generic dao pattern for the dao-objects.</p>
  
  <p>For an unknown reason I receive this error:</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'klantController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private service.KlantDao controllers.KlantController.klantDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [service.KlantDao] 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)}
  </code></pre>
  
  <p>This is the generic dao interface:</p>
  
  <pre><code>package service;
  
  import java.util.List;
  
  public interface GenericDao&lt;T&gt; {
  
      public List&lt;T&gt; findAll();
      public T update(T object);
      public T get(Long id);
      public void delete(T object);
      public void insert(T object);
      public boolean exists(Long id) ;
  }
  </code></pre>
  
  <p>The generic dao class:</p>
  
  <pre><code>package service;
  
  import java.util.List;
  import javax.persistence.EntityManager;
  import javax.persistence.PersistenceContext;
  import org.springframework.transaction.annotation.Transactional;
  
  @Transactional
  public class GenericDaoJpa&lt;T&gt; implements GenericDao&lt;T&gt; {
  
      private Class&lt;T&gt; type;
      private EntityManager em;
  
      public GenericDaoJpa(Class&lt;T&gt; type) {
          super();
          this.type = type;
      }
  
      @PersistenceContext
      public void setEntityManager(EntityManager em) {
          this.em = em;
      }
  
      @Transactional(readOnly = true)
      @Override
      public T get(Long id) {
          T entity = this.em.find(this.type, id);
          return entity;
      }
  
      @Transactional(readOnly = true)
      @Override
      public List&lt;T&gt; findAll() {
          return this.em.createQuery(
                  "select entity from " + this.type.getName() + " entity").getResultList();
      }
  
      //@Transactional
      @Override
      public void insert(T object) {
          em.persist(object);
      }
  
      //@Transactional
      @Override
      public void delete(T object) {
          em.remove(em.merge(object));
      }
  
      @Transactional(readOnly = true)
      @Override
      public boolean exists(Long id) {
          T entity = this.em.find(this.type, id);
          return entity != null;
      }
  
      @Override
      public T update(T object) {
          return em.merge(object);
      }
  }
  </code></pre>
  
  <p>The concrete DAO I'm try to inject:</p>
  
  <pre><code>package service;
  import domain.Klant;
  
  public class KlantDao extends GenericDaoJpa&lt;Klant&gt;
  {
      public KlantDao()
      {
          super(Klant.class);
      }
  }
  </code></pre>
  
  <p>The controller class where I'm trying to inject the bean:</p>
  
  <pre><code>@Controller
  public class KlantController 
  {
      @Autowired
      private KlantDao klantDao;
  
  // route methods
  
      public KlantDao getKlantDao() {
          return klantDao;
      }
  
      public void setKlantDao(KlantDao klantDao) {
          this.klantDao = klantDao;
      }
  }
  </code></pre>
  
  <p>In the dispatcher servlet I configure the bean like this:</p>
  
  <pre><code>&lt;bean id="klantDao" class="service.KlantDao"/&gt;
  </code></pre>
  
  <p>I think the problem is something with the autowiring. I've tried a lot of combinations of settings but I always receive the same error.</p>
  
  <p>I hope someone can help.
  Thanks</p>