title: Why NoUniqueBeanDefinitionException: No qualifying bean of type is defined: expected single matching bean but found 2
body: <p>In this small app, I have used <code>@Autowired</code> annotation along with <code>@Qualifier</code> annotation to config the dependencies, but still an exception is thrown as mentioned below.</p>
  
  <p><strong>Pizaa class</strong></p>
  
  <pre><code>public class Pizza {
  
      private Address deliverydest;
  
      @Autowired
      @Qualifier("ForPizza")
      public void setDeliverydest(Address deliverydest) {
          this.deliverydest = deliverydest;
      }
  }
  </code></pre>
  
  <p><strong>Spring Context Configuration</strong></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:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"&gt;
  
      &lt;bean id="pizza" class="com.test.Shopping.Pizza" /&gt;
  
      &lt;bean id="Cust1Address" class="com.test.Shopping.Address" /&gt;
  
      &lt;bean id="dest1" class="com.test.Shopping.Address" &gt;
          &lt;qualifier value="ForPizza" /&gt;
          &lt;property name="buildingno" value="flat1/door2" /&gt;
      &lt;/bean&gt;
  
      &lt;bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>The exception thrown is</p>
  
  <pre><code>Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pizza': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.test.Shopping.Pizza.setDeliverydest(com.test.Shopping.Address); nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.test.Shopping.Address] is defined: expected single matching bean but found 2: Cust1Address,dest1
  
  Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.test.Shopping.Pizza.setDeliverydest(com.test.Shopping.Address); nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.test.Shopping.Address] is defined: expected single matching bean but found 2: Cust1Address,dest1
  
  Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.test.Shopping.Address] is defined: expected single matching bean but found 2: Cust1Address,dest1
  </code></pre>
  
  <p>. </p>
  
  <p>Now why is the Spring not considering the <code>@Qualifier</code> annotation to find the correct bean <strong>dest1</strong> having qualifier <code>value="ForPizza"</code> ?</p>