ZTS*_*ean 5 java spring yaml spring-boot
我是 Spring-Boot 的新手,在将 application.yml 文件中的属性值绑定到用@ConfigurationProperies
.
在 application.yml 中:
aaa:
what-1word-is: true
Run Code Online (Sandbox Code Playgroud)
在带@ConfigurationProperties
注释的类中:
@Data
@Configuration
@ConfigurationProperties(prefix = "aaa")
public class Test
{
private boolean what1WordIs;
}
Run Code Online (Sandbox Code Playgroud)
我尝试为该属性使用不同的名称,但它们都不起作用;
what1WordIs
总是false
。名字我试过了,
what-1-word-is
,
what-1word-is
,
what1-word-is
,
what-1Word-is
。仅what1-word-is
有效(what1WordIs
在配置类中设置为true
)
Spring 是否能够绑定名称中带有数字的属性?
小智 1
我将提出一些与要求不同的建议。我可能建议不要在属性文件中允许数字。
如果可能的话,您可以尝试将属性名称设置为如下所示:
aaa:
what-single-word-is
或者可能更短一些:
aaa:
single-word
无法使用@ConfigurationProperties读取yaml的复杂对象。整数无法转换为字符串
归档时间: |
|
查看次数: |
8569 次 |
最近记录: |