Is it possible to inject a null or blank string as the default value that will be used in a spring file if the property is not specified? Currently the best I have is
<constructor-arg index="1" value="@{data.url:""}"/>
which resolves to ""
in code
In Spring dependency injection, we can inject null and empty values. In XML configuration, null value is injected using <null> element.
Answer. Yes, Spring allows injecting null or empty String values.
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.
Have you tried using SpEL? Something like this maybe:
<constructor-arg index="1" value="#{'${data.url}'==null?'':'${data.url}'}"/>
Update
I just remembered that there's an easier way (as nicely described here). Try:
<constructor-arg index="1" value="${data.url:''}"/>
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