Can we use @Required and @Autowired and @Qualifier on the same setter method.
When I try to use in the below mentioned way I have getting compile time error saying "The annotation @Qualifier is disallowed for this location"
My configuration file isCode:public class Customer { private Person person; private int type; private String action; @Qualifier("PersonBean1") @Autowired() @Required() public void setPerson(Person person) { this.person = person; } //setter and getters for type,action }
Could anyone explain why this cannot be done ?Code:<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-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <context:annotation-config/> <bean id="CustomerBean" class="Customer"> <property name="action" value="buy" /> <property name="type" value="1" /> </bean> <bean id="PersonBean" class="Person"> <property name="name" value="mkyong" /> <property name="address" value="address 123" /> <property name="age" value="28" /> </bean> <bean id="PersonBean1" class="Person"> <property name="name" value="mkyong" /> <property name="address" value="address 123" /> <property name="age" value="28" /> </bean> </beans>


Reply With Quote