springpropertiesnulldefault-value

Specify default property value as NULL in Spring


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?


Solution

  • 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