要求是我们有一个接口并且有很多实现。现在,在请求输入的基础上,我需要选择实现,例如可以说请求对象中有一个clientID参数,并且在clientID的基础上,我需要选择实现类。Spring Bean创建帮助
<bean id = "clientService" class =" com.ecourt.CLientServiceImpl">
<property name="someInterface" ref = "this needs to be changed for every client base on the request Input"/>
</bean>
<!-- Below mentioned Beans are Impl of "someInterface" property of above define bean --!>
<bean id ="clientOneImpl" class = "com.ecourt.clienOneImpl"/>
<bean id ="clientTwoImpl" class = "com.ecourt.clienTwoImpl"/>
可能的解决方案可在规划环境地政司表达,但到现在为止,我设法找到了只有这个:
<property name="someInterface" ref="#{clientID =='101'?clientOneImpl:clientTwoImpl}"/>
但有了这个条件语句,我可以处理最大的两个客户端。有没有办法处理两个以上的客户?有没有办法做到这一点?任何帮助将不胜感激。
您可以为每个实现定义具有clientID作为id属性的bean。通过传递clientID来返回基于给定clientID的实际实现来调用getBean()。 – Pokuri