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?
It appears you can do the following:
and
You can try use Spring EL.
It is better to use Spring EL in such way
it checks whether
email.password
is specified and sets it tonull
(not"null"
String) otherwisehave a look at PropertyPlaceholderConfigurer#setNullValue(String)
It states that:
So just define the string "null" to map the null value in your PropertyPlaceholderConfigurer:
Now you can use it in your properties files: