Spring Boot YAML:设置 null 属性值

Jar*_*rdo 7 java spring yaml spring-boot

null我在设置属性值时遇到问题。

这是在 YAML 文件中定义该值的方式:

my-property: null
Run Code Online (Sandbox Code Playgroud)

这就是我在代码中注入它的方式:

@Value("${my-property}")
private String myProperty;
Run Code Online (Sandbox Code Playgroud)

由于某种原因,Spring 不断注入空字符串 ("") 而不是null. 我是否遗漏了什么或者这是 Spring 中的错误?

Co *_* ti 1

尝试使用而不是$使用 this #。或者试试这个@Value("${<my-property>}")