Professional Documents
Culture Documents
Autowire Annotation Using Qualifier:: Package
Autowire Annotation Using Qualifier:: Package
Autowire Annotation Using Qualifier:: Package
Address.java
package com.app.model;
==
Employee.java
package com.app.model;
import
org.springframework.beans.factory.annotation.Aut
owired;
import
org.springframework.beans.factory.annotation.Qua
lifier;
public Employee() {
super();
}
}
= =
beans.xml
<beans
xmlns="http://www.springframework.org/schema/bea
ns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
xmlns:p="http://www.springframework.org/schema/p
"
xmlns:c="http://www.springframework.org/schema/c
"
xmlns:context="http://www.springframework.org/sc
hema/context"
xsi:schemaLocation="http://www.springframework.o
rg/schema/beans
http://www.springframework.org/schema/beans/spri
ng-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/sp
ring-context-3.0.xsd">
<context:annotation-config/>
<bean id="employee"
class="com.app.model.Employee">
</bean>
<bean id="abcd"
class="com.app.model.Address">
<property name="doorId" value="8585"/>
</bean>
<bean id="mnop"
class="com.app.model.Address">
<property name="doorId" value="9589"/>
</bean>
</beans>
= =
Test.java
package com.app.test;
import
org.springframework.context.support.AbstractAppl
icationContext;
import
org.springframework.context.support.ClassPathXml
ApplicationContext;
import com.app.model.Employee;
System.out.println(employee.getAddress().getDoor
Id());
}
===
Output: