小编典典

Spring配置中的条件语句

spring

如何在Spring配置文件中包含条件语句

我有四季豆(b),其值取决于属性(a)的值。a是根据其运行环境动态设置的。

if (a)
 b="yes"
else
 b="no"

我该如何在spring config中编写代码?


阅读 372

收藏
2020-04-21

共1个答案

小编典典

正如Ryan所说,SpEL可以提供帮助。你应该能够在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>
2020-04-21