【发布时间】:2019-03-26 17:43:54
【问题描述】:
我遇到了下一个情况:我已经从 Spring Boot 1.5.x 迁移了我的应用程序 到 Spring Boot 2.0.5。
我有下一堂课:
@ConfigurationProperties(prefix = "some.property")
public class Myclass {
@Getter
@Setter
private List<String> list;
}
我也有这样的 yml 配置:
some:
property:
list:
- value 1
- value 2
- value 3
此配置是从远程 spring-cloud-config 服务器获取的。
如果我尝试运行应用程序,我会遇到下一个异常:
org.springframework.boot.
context.properties.bind.BindException: Failed to bind properties under
'some.property' to Myclass
Description:
Property: some.property.list[0]
Value: value 1
Origin: "some.property.list[0]" from property source "bootstrapProperties"
Reason: The elements
[some.property.list[0],some.property.list[1],some.property.list[2]] were
left unbound.
Property: some.property.list[1]
Value: value 2
Origin: "some.property.list[1]" from property source "bootstrapProperties"
Reason: The elements
[some.property.list[0],some.property.list[1],some.property.list[2]] were
left unbound.
Property: some.property.list[2]
Value: value 3
Origin: "some.property.list[2]" from property source "bootstrapProperties"
Reason: The elements
[some.property.list[0],some.property.list[1],some.property.list[2]] were
left unbound.
但如果我使用本地 bootstrap.yml 文件而不是远程配置服务器 - 一切都很好。
有人遇到过同样的问题吗?我真的需要你的帮助。
附: Spring config server 也有 2.0.5 版本。
【问题讨论】:
-
您似乎省略了 $ 和花括号 {}。你应该这样声明:@Value("${some.property.list}")
-
Ebert Toribio,我在上面的示例中犯了一个错误,实际上我使用了@ConfigurationProperties(prefix = "some.property")。对此感到抱歉。
-
你有同样的问题吗?
-
是的,问题和上面一样。
-
您可以这样放置您的属性吗:Value1、Value2、Value3。正如我所见,您正在列出值,但您需要在同一行中用逗号分隔它们
标签: spring-boot spring-cloud-config spring-config