Springs @Qualifier annotation not working
<p>Am playing around with <code>@Qualifier</code> along with <code>@Autowired</code>.<br>
Here is my application context file     </p>

<pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;

&lt;bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" /&gt;

&lt;bean id="helloBean" class="com.springex1.HelloWorld1"&gt;
    &lt;property name="name" value="Mkyong" /&gt;
&lt;/bean&gt;

&lt;bean id="address1" class="com.springex1.Address" &gt;
    &lt;property name="street" value="sahajanand" /&gt;
&lt;/bean&gt;

&lt;bean id="address2" class="com.springex1.Address" &gt;
    &lt;property name="street" value="pune" /&gt;
&lt;/bean&gt;
</code></pre>

<p>    </p>

<p>Here are my Java classes<br>
HelloWorld1.java    </p>

<pre><code>package com.springex1;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

public class HelloWorld1 {
private String name;

@Autowired
@Qualifier("address1")
private Address address = null; 

public void setName(String name) {
    this.name = name;
}


public void setAddress(Address address) {
    this.address = address;
}

public void printHelloWithAddress() {
    System.out.println("Hello ! " + name + " your street " + address.getStreet());
}


}
</code></pre>

<p>Address.java    </p>

<pre><code>package com.springex1;

public class Address {
private String street = "";

public void setStreet(String street) {
    this.street = street;
}

public String getStreet(){
    return this.street;
}
}
</code></pre>

<p>Here is where I am trying to get things to run - App.java    </p>

<pre><code>package com.springex1;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class App {

public static void main(String[] args) {

    call1("appContext1.xml");           
}

public static void call1(String appContext){
    ApplicationContext context = new ClassPathXmlApplicationContext(appContext);

    HelloWorld1 obj = (HelloWorld1) context.getBean("helloBean");
    obj.printHelloWithAddress();
}     
} 
</code></pre>

<p>I keep getting this exception -ideally I should not since I have the @Qualifier annotation with the id 'address1' defined - so it should not throw an exception    </p>

<blockquote>
  <p>WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'helloBean': Unsatisfied dependency expressed through field 'address': No qualifying bean of type [com.springex1.Address] is defined: expected single matching bean but found 2: address1,address2; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.springex1.Address] is defined: expected single matching bean but found 2: address1,address2
  Exception in thread "main" org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'helloBean': Unsatisfied dependency expressed through field 'address': No qualifying bean of type [com.springex1.Address] is defined: expected single matching bean but found 2: address1,address2; nested exception is org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.springex1.Address] is defined: expected single matching bean but found 2: address1,address2
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)</p>
</blockquote>

<p>I am using spring 4.3 release version - this is the only dependency in my pom    </p>

<pre><code>    &lt;dependency&gt;
    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
    &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
    &lt;version&gt;4.3.0.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- 
&lt;dependency&gt;
    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
    &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
    &lt;version&gt;4.3.0.RELEASE&lt;/version&gt;
&lt;/dependency&gt;
 --&gt;
</code></pre>