Spring – Conditional statement inside Spring config


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 based on environment it runs.

if (a)

How do i code this in spring config?

Best Solution

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 id="bean" class="com.my.MyBean">
    <property name="property" value="#{ flag ? 'yes' : 'no' }"/>