java 有没有办法在spring mvc3的xml中设置if/else条件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13293188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to have if/else conditions in an xml in spring mvc3?
提问by birdy
I have a properties file defined in my xml:
我在我的 xml 中定义了一个属性文件:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/db.properties"></property>
</bean>
I have a property in the file:
我在文件中有一个属性:
someprop = one
Question
问题
In my XML I would like to either add/remove a property in a bean definition. For example:
在我的 XML 中,我想在 bean 定义中添加/删除一个属性。例如:
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.internal.url}" />
<!--I want to add/remove the line below based on value in property file-->
<property name="username" value="${jdbc.internal.username}" />
</bean>
采纳答案by Aravind Yarram
This might be possible using SpringEL. Read the Expression support for defining bean definitionssection here.
使用 SpringEL 这可能是可能的。在此处阅读用于定义 bean 定义的表达式支持部分。
If this is to handle multiple environments then Spring 3.1 provides bean definition profilesand Environmentabstractions.
如果这是为了处理多个环境,那么 Spring 3.1 提供了bean 定义配置文件和环境抽象。