【发布时间】:2016-03-06 14:28:33
【问题描述】:
我正在尝试使用 SpringBoot 版本 1.3.0.RELEASE 在 application.yml 中将默认值定义为空值。目标是能够使用带有ConfigurationProperties 注释的类来引用它
-- application.yml --
test.foo: ${test.bar:#{null}}
但它不起作用。
如果test.bar的值没有定义,将test.foo设置为null(默认值)
我的依赖项中已经有了 spring-el。我不想用PropertyPlaceholderConfigurer.setNullValue
它似乎在@Value 中有效,但在application.yml 中无效(请参阅http://farenda.com/spring/spring-inject-null-value/)
这是一个错误,还是 yaml 不是为此而设计的? 我尝试了http://yaml.org/type/null.html 中的所有值,但也没有用
谢谢
【问题讨论】:
-
我们不会在配置文件中将 SpEL 表达式应用为explained in the documentation
-
谢谢,如果我明白了,唯一的方法是使用
PropertyPlaceholderConfigurer.setNullValue?
标签: null spring-boot yaml default-value spring-el