mardi 24 mai 2016

Spring IoC: Conditional Injection in run time

How can I conditionally inject a bean externally using the framework ( not creating a factory class)?

In below scenario both childBeans will be instantiated already while but injected into parent bean in run time based on condition.

<bean id=ChildBean1>
<bean id=ChildBean2>
<parentBean name='parentBean' lazy-init="true">
   <property name='flag'>

   <somecondition flag=1/>  
   <property name='child' ref ='childBean1'/>
   <somecondition flag=2/> 
   <property name='child' ref ='childBean2'/>
</parentBean>

Aucun commentaire:

Enregistrer un commentaire