小编kho*_*g07的帖子

如何在Spring Boot中的application.yml中定义默认空值

我正在尝试使用SpringBoot版本1.3.0.RELEASE在application.yml中将默认值定义为null值.目标是能够使用带ConfigurationProperties注释的类来引用它

-- application.yml --
test.foo: ${test.bar:#{null}}
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

如果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中尝试了所有值,但它也没有用

谢谢

null yaml default-value spring-el spring-boot

10
推荐指数
1
解决办法
6600
查看次数

标签 统计

default-value ×1

null ×1

spring-boot ×1

spring-el ×1

yaml ×1