In Spring 4, using the @Value annotation, what is the correct way to specify a default system property if the specified property does not exist?
While this works for the case without default:
@Value("${myapp.temp}") private String tempDirectory;
This does not work when I need the default:
@Value("#{myapp.temp ?: systemProperties.java.io.tmpdir}") private String tempDirectory;
And it does not:
@Value("#{myapp.temp ?: systemProperties(java.io.tmpdir)}") private String tempDirectory;
Both of them give me an exception while Spring is trying to create a bean:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationService': Invocation of init method failed; nested exception is java.lang.NullPointerException
Can this be done?
java spring
David h
source share