Is there a way to have if/else conditions in an xml in spring mvc3?

15,264

This might be possible using SpringEL. Read the Expression support for defining bean definitions section here.

If this is to handle multiple environments then Spring 3.1 provides bean definition profiles and Environment abstractions.

Share:
15,264
birdy
Author by

birdy

Updated on June 27, 2022

Comments

  • birdy
    birdy almost 2 years

    I have a properties file defined in my 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:

    <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>