Spring配置中的条件语句 [英] Conditional statement inside Spring config
本文介绍了Spring配置中的条件语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在spring配置文件中包含条件语句
How to have conditional statement within a spring configuration file
我有String bean(b),其值取决于属性(a)的值. a是根据其运行环境动态设置的.
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)
b="yes"
else
b="no"
如何在spring config中对此进行编码?
How do i code this in spring config?
推荐答案
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>
这篇关于Spring配置中的条件语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文