Specify default property value as NULL in Spring

Ondrej Bozek picture Ondrej Bozek · May 24, 2013 · Viewed 40.9k times · Source

I want to define default property value in Spring XML configuration file. I want this default value to be null.

Something like this:

...
<ctx:property-placeholder location="file://${configuration.location}" 
                          ignore-unresolvable="true" order="2" 
                          properties-ref="defaultConfiguration"/>

<util:properties id="defaultConfiguration">
    <prop key="email.username" >
        <null />
    </prop>  
    <prop key="email.password">
        <null />
    </prop>  
</util:properties>
...

This doesn't work. Is it even possible to define null default values for properties in Spring XML configuration?

Answer

Anton Kirillov picture Anton Kirillov · Jul 4, 2013

It is better to use Spring EL in such way

<property name="password" value="${email.password:#{null}}"/>

it checks whether email.password is specified and sets it to null (not "null" String) otherwise