Bean定义中使用的Spring表达式语言(SpEL)中的条件

ser*_*nni 4 spring conditional expression

到目前为止,SpEL在Spring 3.0中使用,

我想问一下,是否可以执行以下操作(在bean定义.xml中):

<c:choose>

  <c:when test="#{prop=='a'}">
   <bean class="BeanA"/>
  </c:when>

  <c:otherwise>
   <bean class="BeanB"/>
  </c:otherwise>

</c:choose>
Run Code Online (Sandbox Code Playgroud)

Someth.喜欢在jstl.

谢谢你的帮助.

小智 5

环境配置文件/环境特定bean将在Spring 3.1中提供,应该很快就会发布 - 所以你可能想要等待它.

Spring 3.0中没有对条件bean的内置支持.但是,可以通过使用PropertyPlaceholderConfigurers和/或FactoryBeans来实现.