title: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException:
body: <p>i'm trying to create example from spring transaction with apache tomcat and postgresql but get error Injection of autowired dependencies failed</p>
  
  <p>Exception</p>
  
  <pre><code>javax.servlet.ServletException: Servlet.init() for servlet dispatcher threw exception
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
      org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
      java.lang.Thread.run(Thread.java:724)
  
  root cause
  
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private DAO.TblUserManager_DAO Controllers.LoginController.user; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [DAO.TblUserManager_DAO] is defined: expected single matching bean but found 2: [tblUserManager_DAOImpl, TblUserManager_DAOImpl]
      org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
      org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
      javax.servlet.GenericServlet.init(GenericServlet.java:212)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
      org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
      java.lang.Thread.run(Thread.java:724)
  
  root cause
  
  org.springframework.beans.factory.BeanCreationException: Could not autowire field: private DAO.TblUserManager_DAO Controllers.LoginController.user; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [DAO.TblUserManager_DAO] is defined: expected single matching bean but found 2: [tblUserManager_DAOImpl, TblUserManager_DAOImpl]
      org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)
      org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
      org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
      org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
      javax.servlet.GenericServlet.init(GenericServlet.java:212)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
      org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
      java.lang.Thread.run(Thread.java:724)
  
  root cause
  
  org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [DAO.TblUserManager_DAO] is defined: expected single matching bean but found 2: [tblUserManager_DAOImpl, TblUserManager_DAOImpl]
      org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:800)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:707)
      org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
      org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
      org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
      org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585)
      org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
      org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
      org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:631)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:588)
      org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:645)
      org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:508)
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:449)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:133)
      javax.servlet.GenericServlet.init(GenericServlet.java:212)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
      org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
      org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
      org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
      java.lang.Thread.run(Thread.java:724)
  </code></pre>
  
  <p>my dispacher-servlet.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans  xmlns="http://www.springframework.org/schema/beans"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:p="http://www.springframework.org/schema/p"
          xmlns:aop="http://www.springframework.org/schema/aop"
          xmlns:mvc="http://www.springframework.org/schema/mvc"
          xmlns:context="http://www.springframework.org/schema/context"
          xmlns:tx="http://www.springframework.org/schema/tx"
          xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
         http://www.springframework.org/schema/mvc
         http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd        
         http://www.springframework.org/schema/context 
         http://www.springframework.org/schema/context/spring-context-2.5.xsd"&gt;
  
      &lt;context:annotation-config /&gt;
      &lt;context:component-scan base-package="Controllers" /&gt; 
      &lt;context:component-scan base-package="DAO" /&gt;
      &lt;mvc:annotation-driven /&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt; 
  
  
      &lt;bean id="viewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver"
            p:prefix="/WEB-INF/jsp/"
            p:suffix=".jsp" /&gt;
  
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
          &lt;property name="driverClassName" value="org.postgresql.Driver" /&gt;
          &lt;property name="url" value="jdbc:postgresql://localhost:5432/car" /&gt;
          &lt;property name="username" value="----" /&gt;
          &lt;property name="password" value="-----" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
          &lt;property name="annotatedClasses" &gt;
              &lt;list&gt;
                  &lt;value&gt;DAOModel.Tblusers&lt;/value&gt;
                  &lt;value&gt;DAOModel.Tblcars&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="packagesToScan" value="DAOModel" /&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
          &lt;!-- &lt;property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" /&gt; --&gt;
      &lt;/bean&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" &gt;
          &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
      &lt;/bean&gt;
      &lt;bean id = "Tblusers_DAOImpl" class="DAO.Tblusers_DAOImpl"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
      &lt;/bean&gt;
     &lt;bean id = "TblUserManager_DAOImpl" class="DAO.TblUserManager_DAOImpl"&gt;
  
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>my repository,service,component</p>
  
  <pre><code>    @Component
      public interface Tblusers_DAO {
          public void adduser(Tblusers user);
      }
  
  
      @Repository
      public class Tblusers_DAOImpl implements Tblusers_DAO{
  
          @Autowired
          private SessionFactory sessionFactory;
  
          @Override
          public void adduser(Tblusers user) {
              this.getSessionFactory().getCurrentSession().saveOrUpdate(user);
          }
  
  
          public SessionFactory getSessionFactory() {
              return sessionFactory;
          }
  
  
          public void setSessionFactory(SessionFactory sessionFactory) {
              this.sessionFactory = sessionFactory;
          }
      }
  
  
  
  @Component
  public interface TblUserManager_DAO {
      public void adduser(Tblusers user);
  }
  
  
  
  @Service
  public class TblUserManager_DAOImpl implements TblUserManager_DAO{
  
      @Autowired
      private TblUserManager_DAO dao;
  
      @Override
      @Transactional
      public void adduser(Tblusers user) {
         dao.adduser(user);
      }
  
      public void setDao(TblUserManager_DAO dao) {
          this.dao = dao;
      }
  
  }
  </code></pre>
  
  <p>and Controller </p>
  
  <pre><code>public class LoginController {
  
      @Autowired
      private  TblUserManager_DAO user;
      @RequestMapping(value = "/Login", method = RequestMethod.POST)
      public ModelAndView setLgin(@ModelAttribute("LoginModel") LoginModel login) {
          ModelAndView model = new ModelAndView();
          Tblusers user2=new Tblusers();
          user2.setTblusersId(3);
          user2.setTblusersFamily(login.getUsername());
          user2.setTblusersPassword(login.getPassword());
          user.adduser(user2);
          model.addObject("Hello", login.getUsername());
          return model;
      }
   public void setUser(TblUserManager_DAO user) {
          this.user = user;
      }
  
  }
  </code></pre>