版本2中的URL中带有URL的Spring Boot YAML配置不再正确加载

Kol*_*l00 4 yaml snakeyaml spring-boot

我将应用程序从Spring Boot 1.5迁移到2.0,并且YAML属性之一不再正确加载。以下配置代码段:

myapp
  serviceUrls:
    'https://example.org/test': 'https://test.example.org/Endpoint'
Run Code Online (Sandbox Code Playgroud)

映射到此配置类:

@ConfigurationProperties(prefix = "myapp", ignoreUnknownFields = false)
public final class MyAppProperties {
  private Map<String, String> serviceUrls = new HashMap<>();
  //[...]
}
Run Code Online (Sandbox Code Playgroud)
  • 在Spring Boot 1.5中,它通过https://example.org/test-> https://test.example.org/Endpoint; 加载为地图。
  • 但是在Spring Boot 2.0中,冒号和斜杠将从map键httpsexample.orgtest->中消失https://test.example.org/Endpoint

我在迁移指南中找不到任何提及。Spring Boot 2中的YAML解析是否已更改?有没有更好的方法来编写以URL为键的YAML映射?

Kol*_*l00 8

我应该检查GitHub问题...有人报告了类似的问题。解决方案是使用“括号语法”,不幸的是,该文件几乎没有记录,将键括在括号内:

myapp
  serviceUrls:
    '[https://example.org/test]': 'https://test.example.org/Endpoint'
Run Code Online (Sandbox Code Playgroud)