Finally, I used the following: I have setter ( setClassValue(Class classValue) ) in the java code for the class I want to use. Then I set the autowire-candidate property to false in the bean so that it will not be used by default:
<bean id="beanA" class="Class" autowire-candidate="false"> <constructor-arg><value>valueA1</value></constructor-arg> <constructor-arg><value>valueA2</value></constructor-arg> </bean> <bean id="beanB" class="Class" > <constructor-arg><value>valueB1</value></constructor-arg> <constructor-arg><value>valueB2</value></constructor-arg> </bean>
Then in the xml file, where I define the bean of the class, which will be the @Autowired Class , I use the java method setClassValue(Class classValue) as follows:
<bean id="classThatAutowire" class="ClassThatAutowire" > <property name="classValue" ref="beanA" /> </bean>
In Java code, yo will be @Autowired beanB , and then install beanA . This is not the best practice, but it works.
source share