【发布时间】:2017-10-07 04:15:14
【问题描述】:
我一直在使用带有 YAML 的 Spring Boot 应用程序进行外部配置,到目前为止效果很好。一个玩具例子:
@Component
@ConfigurationProperties
class MyConfig {
String aaa;
Foo foo;
static class Foo {
String bar;
}
}
然后是具有以下属性的 yaml 文件:
aaa: hello
foo.bar: world
我的问题是我真的需要在我的配置中添加一个 JsonObject。我首先尝试将其作为字段添加到 MyConfig 类中,然后编写以下我认为在语法上有效的 YAML 文件:
aaa: hello
from:
{
"first_initial": "D",
"last_initial": "E"
}
foo.bar: world
Spring 抛出以下错误:Cannot access indexed value in property referenced...
我最终将值改为纯字符串,并使用 > 折叠标签将其放入 YAML,但这意味着我必须在我的代码中手动将字符串解析为 JsonObject。
有人知道怎么做吗?
【问题讨论】:
标签: spring spring-boot yaml snakeyaml