在Spring Boot中在Yaml中转义Map键中的点 [英] Escaping a dot in a Map key in Yaml in Spring Boot

查看:407
本文介绍了在Spring Boot中在Yaml中转义Map键中的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下yml配置:

foo:
  bar.com:
    a: b
  baz.com:
    a: c

在下一个类中,Spring尝试使用键"bar"和"baz"注入地图,将点作为分隔符:

With a following class Spring tries to inject map with keys 'bar' and 'baz', treating dots as separator:

public class JavaBean {
    private Map<String, AnotherBean> foo;
(...)
}

我尝试引用密钥(即"bar.com"或"bar.com"),但无济于事-仍然是同样的问题.有办法解决吗?

I have tried quoting the key (i.e. 'bar.com' or "bar.com") but to no avail - still the same problem. Is there a way around this?

推荐答案

@fivetenwill的答案的稍作修订,该版本在Spring Boot 1.4.3上对我有效.

A slight revision of @fivetenwill's answer, which works for me on Spring Boot 1.4.3.RELEASE:

foo:
  "[bar.com]":
    a: b
  "[baz.com]":
    a: c

您需要将括号括在引号内,否则YAML解析器基本上会在到达Spring之前将其丢弃,并且它们不会成为属性名称.

You need the brackets to be inside quotes, otherwise the YAML parser basically discards them before they get to Spring, and they don't make it into the property name.

这篇关于在Spring Boot中在Yaml中转义Map键中的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆