Reputation: 1185
I am trying to achieve the below functionality using Spring but have not succeeded till now.
Create a spring bean "testBean" in XML file and dynamically point it to class "A" or "B" depending on whether some system property "C" has been set or not. I want to handle this at the XML configuration file level itself. The rest of the application should be able to use the bean "testBean" seamlessly.
Please let me know how can this be done using Spring? Let me know if any other details are required.
Thanks in advance.
Upvotes: 3
Views: 1549
Reputation: 69002
You could use the expression language to configure your testBean like this (not tested):
<bean id="testBean" class="com.test.TestBean">
<property name="pointer" value="#{ systemProperties['C'] != null ? 'com.test.A' : 'com.test.B' }"/>
</bean>
See the documentation for further reference.
Relevant parts:
Upvotes: 3