title: NoUniqueBeanDefinitionException: no qualifying bean of type. I defined, expected a single matching bean, but I found 2
body: <p>We've been searching around a bit on both the internet and our paperback courses but can't seem to find a solution to our problem:</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [services.GebruikerDAO] is defined: expected single matching bean but found 2: gebruikerDAO,GebruikerDAO
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:863)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:768)
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:486)
  ... 58 more
  </code></pre>
  
  <p>To sketch some background information: we have to make a small website using java jsp pages and all, together with spring security and maven using a DB to get information and check for information. Following will be all our files.</p>
  
  <p>This is our GebruikerDAO class:</p>
  
  <pre><code>package services;
  import domein.Gebruiker;
  
  public interface GebruikerDAO extends GenericDao&lt;Gebruiker&gt;{
  
      public Gebruiker getGebruikerByStamnummer(String stamnummer);
  
  }
  </code></pre>
  
  <p>This is our JpaGebruikerDao class:</p>
  
  <pre><code>@Repository("gebruikerDAO")
  public class JpaGebruikerDao extends GenericDaoJpa&lt;Gebruiker&gt; implements GebruikerDAO{
  
      @PersistenceContext
      private EntityManager em;
  
      public JpaGebruikerDao()
      {
          super(Gebruiker.class);
      }
  
      /*@Override
      @Transactional
      public List&lt;Gebruiker&gt; findAll() {
          CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
          CriteriaQuery&lt;Gebruiker&gt; criteriaQuery = criteriaBuilder.createQuery(Gebruiker.class);
  
          Root&lt;Gebruiker&gt; gebruiker = criteriaQuery.from(Gebruiker.class);
  
          criteriaQuery.orderBy(criteriaBuilder.desc(gebruiker.get(Gebruiker_.familienaam)));
  
      // JPQL select 
          criteriaQuery.select(gebruiker);
  
          TypedQuery&lt;Gebruiker&gt; query = em.createQuery(criteriaQuery);
          return query.getResultList();
      }*/
  
      // CRUD methods
      @Override
      @Transactional
      public Gebruiker update(Gebruiker gebruiker) {
          return em.merge(gebruiker);
      }
  
      @Override
      @Transactional(readOnly = true)
      public Gebruiker get(String id) {
          return em.find(Gebruiker.class, id);
      }
  
      @Override
      @Transactional
      public void insert(Gebruiker gebruiker) {
          em.persist(gebruiker);
      }
  
      @Override
      @Transactional
      public void delete(Gebruiker gebruiker) {
          em.remove(em.merge(gebruiker));
      }
  
      @Override
      public Gebruiker getGebruikerByStamnummer(String stamnummer) {
          return get(stamnummer);
      }
  }
  </code></pre>
  
  <p>This is our Controller class:</p>
  
  <pre><code>@Controller
  public class PlanningController {
  
      @Autowired
      @Qualifier("GebruikerDAO")
      private GebruikerDAO gebruikerDao;
  
      @RequestMapping(value = "/planning", method = RequestMethod.GET)
      public String listGuest(Model model)
      {
          List&lt;Gebruiker&gt; gebruikerlijst = gebruikerDao.findAll();
          List&lt;Student&gt; studentlijst = new ArrayList&lt;&gt;();
  
          for (Gebruiker s : gebruikerlijst) {
              if (s instanceof Student){
                  Student student = (Student)s;
                  if(student.getLokaal() != null)
                  {
                      studentlijst.add(student);
                  }
              }
          }
          // there is more but it just checks for if a timeslot is available in our planning
  </code></pre>
  
  <p>This is our spring-security file:</p>
  
  <pre><code>&lt;beans:beans xmlns="http://www.springframework.org/schema/security"
           xmlns:beans="http://www.springframework.org/schema/beans"
           xmlns:p="http://www.springframework.org/schema/p"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="
              http://www.springframework.org/schema/security
              http://www.springframework.org/schema/security/spring-security-3.1.xsd
              http://www.springframework.org/schema/beans
              http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"&gt;
  
  &lt;beans:import resource="applicationContext.xml"/&gt;
  
  &lt;http auto-config="true"&gt;
      &lt;intercept-url pattern="/admin*" access="hasAnyRole('ROLE_Student', 'ROLE_Promotor', 'ROLE_Coordinator')"/&gt;
      &lt;logout logout-success-url="/planning.htm"/&gt;
      &lt;access-denied-handler ref="accessDeniedHandler"/&gt;
      &lt;remember-me/&gt;
  &lt;/http&gt;
  
  &lt;authentication-manager&gt;
      &lt;authentication-provider&gt;
          &lt;password-encoder hash="sha-256"/&gt;
          &lt;jdbc-user-service data-source-ref="dataSource"
                             users-by-username-query="select StamNummer, WachtwoordEncrypted, 'true' as enabled from gebruiker where StamNummer=?"
                             authorities-by-username-query="select StamNummer, Type as authority from gebruiker where StamNummer=?"
                             role-prefix="ROLE_"
          /&gt;
      &lt;/authentication-provider&gt;
  &lt;/authentication-manager&gt;
  
  &lt;beans:bean class="org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>This is our applicationContext file:</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: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"&gt;
  
      &lt;bean name = "GebruikerDAO" class="services.JpaGebruikerDao"/&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>This is our dispatcher-servlet file:</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:tx="http://www.springframework.org/schema/tx"
     xmlns:mvc="http://www.springframework.org/schema/mvc"
     xmlns:context="http://www.springframework.org/schema/context"
     xmlns:jee="http://www.springframework.org/schema/jee"
     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-3.1.xsd
  http://www.springframework.org/schema/jee
  http://www.springframework.org/schema/jee/spring-jee-3.1.xsd"&gt;   
  
  &lt;mvc:annotation-driven /&gt;
  &lt;context:component-scan base-package="controller"/&gt;
  &lt;context:component-scan base-package="services"/&gt;
  
  &lt;bean id="accessDeniedHandler" class="handler.MyAccessDeniedHandler"&gt;
      &lt;property name="accessDeniedUrl" value="403"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
      &lt;property name="url" value="jdbc:mysql://localhost:3306/bachelorproef"/&gt; &lt;!--  jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull--&gt;
      &lt;property name="username" value="root"/&gt;
      &lt;property name="password" value="root"/&gt;
  &lt;/bean&gt;
  &lt;bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;property name="packagesToScan"&gt;
          &lt;list&gt;
              &lt;value&gt;domein&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
              &lt;property name="showSql" value="true" /&gt; 
              &lt;property name="generateDdl" value="true" /&gt;
              &lt;property name="database" value="MYSQL"/&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager" 
        class=" org.springframework.orm.jpa.JpaTransactionManager "&gt;
      &lt;constructor-arg ref="entityManagerFactory" /&gt;
  &lt;/bean&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;/beans&gt;
  </code></pre>
  
  <p>This is our web.xml file:</p>
  
  <pre><code>&lt;web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-   app_2_4.xsd"&gt;
  &lt;display-name&gt;Spring MVC Application&lt;/display-name&gt; 
  &lt;servlet&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt; 
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; 
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; 
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt; 
      &lt;url-pattern&gt;/&lt;/url-pattern&gt; 
  &lt;/servlet-mapping&gt;
  &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; 
  &lt;/listener&gt;
  &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; 
      &lt;param-value&gt;/WEB-INF/dispatcher-servlet.xml, 
                              /WEB-INF/spring-security2.xml
      &lt;/param-value&gt; 
  &lt;/context-param&gt; 
  &lt;filter&gt;
      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt; 
      &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt; 
  &lt;/filter&gt;
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt; 
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt; 
  &lt;/filter-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>This is our Gebruiker class:</p>
  
  <pre><code>@Entity
  @Table(name = "gebruiker")
  @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  @DiscriminatorColumn(name = "Type")
  public abstract class Gebruiker implements Serializable {
  
  @Id
  @Column(name = "StamNummer")
  private String stamNummer;
  @Column(name = "Familienaam")
  private String familienaam;
  @Column(name = "Voornaam")
  private String voornaam;
  @Column(name = "Email")
  private String email;
  @Column(name = "Wachtwoord")
  private String wachtwoord;
  @Column(name = "Campus")
  private String campus;
  @Transient
  private String naam;
  
  public Gebruiker() {
  
  }
  (+ some extra getters, setters and generatePassword methods)
  </code></pre>
  
  <p>This is our Student class:</p>
  
  <pre><code>@Entity
  @DiscriminatorValue("Student")
  public class Student extends Gebruiker{
  
  @ManyToOne
  private Promotor promotor;
  
  @OneToOne
  @JoinColumn(name = "HuidigDossier_DossierId")
  private Dossier dossier;
  
  @Temporal(TemporalType.TIMESTAMP)
  private Date datumPresentatie;  
  
  private String lokaal;
  (+ some getters, setters and toString)
  </code></pre>
  
  <p>This is our Promotor class:</p>
  
  <pre><code>@Entity
  @DiscriminatorValue("Promotor")
  public class Promotor extends Gebruiker {
  
      @OneToMany(mappedBy="promotor")
      List&lt;Student&gt; studenten;
  
      public Promotor(){
           studenten = new ArrayList&lt;&gt;();
      }
  
      public List&lt;Student&gt; getStudenten() {
          return studenten;
      }
  
      public void setStudenten(List&lt;Student&gt; studenten) {
          this.studenten = studenten;
      }
  
  }
  </code></pre>
  
  <p>This is our BPCoordinator class: </p>
  
  <pre><code>@Entity
  @DiscriminatorValue("Coordinator")
  public class BPCoordinator extends Gebruiker{
  
      public BPCoordinator(){
  
      }
  }
  </code></pre>
  
  <p>I know there is lots of information to be found if the <code>NoUniqueBeanDefinitionException</code> error occurs, but this almost always refers to the entityManager, here he says both gebruikerDAO and GebruikerDAO or something are found and we have no idea where he gets them from or why this error occurs. Most of this code has been almost purely copy paste from other schoolprojects and paperbackcode (our course given by to us by our lectors)</p>
  
  <p>Ideas where and how to fix the issue would be amazing.</p>