In wizards type "Java Project" and Select "Java Project"
Click Next
Enter project name as "AutowiringBeanWithQualifierAnnotationOfJDI", then click Next
Goto Libraries tab, then click on Add External JARs, then select Spring's 21 Framework Jars javax.inject-1.jar and commons-logging-1.1.jar.
Click Finish.
Step.2 Project Explorer Preview
RunMyProgram.java
package com.springexample;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class RunMyProgram {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
JosephCollegeDetails josephCollegeDetails = (JosephCollegeDetails) context.getBean("josephCollegeDetails");
System.out.println("College Details");
System.out.println("---------------");
System.out.println(josephCollegeDetails.getCollege().getCollegeName());
System.out.println(josephCollegeDetails.getCollege().getCity());
System.out.println(josephCollegeDetails.getPrincipalName());
}
}
JosephCollegeDetails.java
package com.springexample;
import javax.inject.Inject;
public class JosephCollegeDetails {
@Inject
@JosephCollegeQualifier(value="josephQualifier")
private College college;
private String principalName;
public College getCollege() {
return college;
}
public void setCollege(College college) {
this.college = college;
}
public String getPrincipalName() {
return principalName;
}
public void setPrincipalName(String principalName) {
this.principalName = principalName;
}
}
College.java
package com.springexample;
public class College {
public String collegeName;
public String city;
public String getCollegeName() {
return collegeName;
}
public void setCollegeName(String collegeName) {
this.collegeName = collegeName;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}