How to have conditional statement within a spring configuration file
I have String bean (b) whose value depends on the value of a property (a). a is set dynamically
As Ryan said SpEL can help. You should be able to do something like this in Spring xml:
<bean id="flag" class="java.lang.Boolean">
<constructor-arg value="#{ systemProperties['system.propery.flag'] ?: false }" />
</bean>
<bean id="bean" class="com.my.MyBean">
<property name="property" value="#{ flag ? 'yes' : 'no' }"/>
</bean>
Try this...It works.. Given Roll,Location,name is in property file and I am reading it above this line.
<bean id="Student" class="beans.Student">
<property name="name" value="#{ ${Roll}== 1 ? '${Location}' : '${name}' }"/>
</bean>
See Spring Expression Language for Spring 3+. Otherwise, you're probably stuck with writing a FactoryBean or something similar.
below is working for me. system property passed as java -Dflag=true -jar project.jar
<bean id="flag" class="java.lang.Boolean">
<constructor-arg value="#{ systemProperties['flag'] ?: false }" />
</bean>
<bean id="bean" class="com.my.MyBean">
<property name="property" value="#{ flag ? 'yes' : 'no' }"/>
</bean>