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

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

问题描述

我有以下 yml 配置:

I have a following yml config:

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.RELEASE:

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天全站免登陆