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?
If no default value is declared explicitly, the default value is the null value. This usually makes sense because a null value can be considered to represent unknown data. In a table definition, default values are listed after the column data type.
To set a default value for primitive types such as boolean and int, we use the literal value: @Value("${some. key:true}") private boolean booleanWithDefaultValue; @Value("${some.
Spring @Value annotation is used to assign default values to variables and method arguments. We can read spring environment variables as well as system variables using @Value annotation. Spring @Value annotation also supports SpEL.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With