Created
August 11, 2017 11:02
-
-
Save cherniag/e913ca5c4754694333d067c802fcbed4 to your computer and use it in GitHub Desktop.
default null value in Spring @value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You must set the nullValue of the PropertyPlaceholderConfigurer. For the example I'm using the string @null but you can also use the empty string as nullValue. | |
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> | |
<!-- config the location(s) of the properties file(s) here --> | |
<property name="nullValue" value="@null" /> | |
</bean> | |
Now you can use the string @null to represent the null value | |
@Value("${stuff.value:@null}") | |
private String value; | |
Please note: The context name space doesn't support the null value at the moment. You can't use | |
<context:property-placeholder null-value="@null" ... /> | |
Tested with Spring 3.1.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment