有没有办法在spring mvc3中的xml中有if/else条件?

bir*_*rdy 6 java spring spring-mvc spring-3

我有一个在我的xml中定义的属性文件:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="/WEB-INF/db.properties"></property>    
</bean>
Run Code Online (Sandbox Code Playgroud)

我在文件中有一个属性:

someprop = one
Run Code Online (Sandbox Code Playgroud)

在我的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>
Run Code Online (Sandbox Code Playgroud)

Ara*_*ram 4

使用 SpringEL 或许可以实现这一点。请阅读此处的用于定义 bean 定义的表达式支持部分。

如果这是为了处理多个环境,那么 Spring 3.1 提供了bean 定义配置文件环境抽象。