Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 811
birdy Avatar asked Nov 08 '12 16:11

birdy


1 Answers

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.

like image 133
Aravind Yarram Avatar answered Nov 19 '22 11:11

Aravind Yarram