Spring 密钥中带有 URL 的启动 YAML 配置不再正确加载版本 2

Spring Boot YAML configuration with URL in key no longer loads correctly with version 2

我正在将我的应用程序从 Spring Boot 1.5 迁移到 2.0,其中一个 YAML 属性不再正确加载。以下配置片段:

myapp
  serviceUrls:
    'https://example.org/test': 'https://test.example.org/Endpoint'

映射到此配置 class:

@ConfigurationProperties(prefix = "myapp", ignoreUnknownFields = false)
public final class MyAppProperties {
  private Map<String, String> serviceUrls = new HashMap<>();
  //[...]
}

我在 migration guide 中找不到任何提及此内容的内容。 Spring Boot 2 中的 YAML 解析是否发生了变化?有没有更好的方法来编写以 URL 作为键的 YAML 映射?

我应该检查 GitHub 个问题...有人报告 a similar problem. The solution is to use the "bracket syntax", which is unfortunately barely documented,将键括在方括号中:

myapp
  serviceUrls:
    '[https://example.org/test]': 'https://test.example.org/Endpoint'