在
Spring 4中,使用@Value注释,如果指定的属性不存在,将系统属性指定为默认值的正确方法是什么?
虽然这适用于非默认情况:
@Value("${myapp.temp}")
private String tempDirectory;
当我需要默认值时,这不起作用:
@Value("#{myapp.temp ?: systemProperties.java.io.tmpdir}")
private String tempDirectory;
这也不是:
@Value("#{myapp.temp ?: systemProperties(java.io.tmpdir)}")
private String tempDirectory;
在Spring尝试创建bean时,这两个都给了我一个例外:
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'configurationService': Invocation of init method failed;
nested exception is java.lang.NullPointerException
可以这样做吗?