|
此版本仍在开发中,目前尚不稳定。如需最新稳定版本,请使用 Spring Cloud Config 5.0.1! |
提供替代格式
环境端点的默认 JSON 格式非常适合 Spring 应用程序使用,因为它可直接映射到 Environment 抽象。
如果您更倾向于其他格式,可以通过在资源路径后添加后缀(“.yml”、“.yaml” 或 “.properties”)来以 YAML 或 Java 属性格式消费相同的数据。
这对于那些不关心 JSON 端点结构或其提供的额外元数据的应用程序非常有用(例如,一个不使用 Spring 的应用程序可能从这种简洁的方法中获益)。
The YAML and properties representations have an additional flag (provided as a boolean query parameter called resolvePlaceholders) to signal that placeholders in the source documents (in the standard Spring ${…} form) should be resolved in the output before rendering, where possible.
This is a useful feature for consumers that do not know about the Spring placeholder conventions.
| 在使用 YAML 或属性格式时存在一些限制,主要体现在元数据的丢失方面。</p><p>例如,JSON 以有序的属性源列表形式进行结构化,其名称与来源相关联。而 YAML 和属性格式则被合并为单一的映射(map),即使原始值来自多个来源,原始源文件的名称也会丢失。此外,YAML 表示形式也不一定忠实于后端仓库中的原始 YAML 源文件。它是从扁平化的属性源列表构建而成的,因此必须对键的格式做出某些假设。 |