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)
https://example.org/test-> https://test.example.org/Endpoint; 加载为地图。httpsexample.orgtest->中消失https://test.example.org/Endpoint。我在迁移指南中找不到任何提及。Spring Boot 2中的YAML解析是否已更改?有没有更好的方法来编写以URL为键的YAML映射?
我应该检查GitHub问题...有人报告了类似的问题。解决方案是使用“括号语法”,不幸的是,该文件几乎没有记录,将键括在括号内:
myapp
serviceUrls:
'[https://example.org/test]': 'https://test.example.org/Endpoint'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1142 次 |
| 最近记录: |