How to escape indicator characters (i.e. : or - ) in YAML

后端 未结 7 2245
醉话见心
醉话见心 2020-11-27 12:13

In a config file, I have a key to which I wish to assign a URL. The problem is that YAML interprets : and - characters as either creating mappings or lists, so it has a pro

7条回答
  •  暖寄归人
    2020-11-27 12:28

    If you're using @ConfigurationProperties with Spring Boot 2 to inject maps with keys that contain colons then you need an additional level of escaping using square brackets inside the quotes because spring only allows alphanumeric and '-' characters, stripping out the rest. Your new key would look like this:

    "[8.11.32.120:8000]": GoogleMapsKeyforThisDomain
    

    See this github issue for reference.

提交回复
热议问题