Serving Plain Text

与其使用 Environment 抽象(或以 YAML 或属性格式表示的备用表示形式),您的应用程序可能需要根据其环境定制的通用纯文本配置文件。Config Server 通过其他端点在 /{application}/{profile}/{label}/{path} 处提供这些文件,其中 applicationprofilelabel 与常规环境端点具有相同的含义,但 path 是文件名路径(例如,log.xml)。此端点的源文件位置与环境端点的源文件位置相同。相同的搜索路径用于属性和 YAML 文件。但是,不会聚合所有匹配的资源,而只会返回第一个匹配的资源。

Instead of using the Environment abstraction (or one of the alternative representations of it in YAML or properties format), your applications might need generic plain-text configuration files that are tailored to their environment. The Config Server provides these through an additional endpoint at /{application}/{profile}/{label}/{path}, where application, profile, and label have the same meaning as the regular environment endpoint, but path is a path to a file name (such as log.xml). The source files for this endpoint are located in the same way as for the environment endpoints. The same search path is used for properties and YAML files. However, instead of aggregating all matching resources, only the first one to match is returned.

在找到资源后,将通过使用提供的应用程序名称、配置文件和标签的有效 Environment 来解决正常格式(${…​}) 中的占位符。通过这种方式,资源端点与环境端点紧密结合。

After a resource is located, placeholders in the normal format (${…​}) are resolved by using the effective Environment for the supplied application name, profile, and label. In this way, the resource endpoint is tightly integrated with the environment endpoints.

与环境配置的源文件一样,profile 用于解析文件名。因此,如果您想要一个特定于配置文件的文件,//development//logback.xml 可以由名为 logback-development.xml 的文件解析(优先于 logback.xml)。

As with the source files for environment configuration, the profile is used to resolve the file name. So, if you want a profile-specific file, //development//logback.xml can be resolved by a file called logback-development.xml (in preference to logback.xml).

如果您不想提供 label 并让服务器使用默认标签,则可以提供 useDefaultLabel 请求参数。因此,default 配置文件的前面示例可以是 /sample/default/nginx.conf?useDefaultLabel

If you do not want to supply the label and let the server use the default label, you can supply a useDefaultLabel request parameter. Consequently, the preceding example for the default profile could be /sample/default/nginx.conf?useDefaultLabel.

目前,Spring Cloud Config 可以为 git、SVN、本机后端和 AWS S3 提供纯文本。对 git、SVN 和本机后端的支持是相同的。AWS S3 的工作方式略有不同。以下部分展示了每个部分的工作方式:

At present, Spring Cloud Config can serve plaintext for git, SVN, native backends, and AWS S3. The support for git, SVN, and native backends is identical. AWS S3 works a bit differently. The following sections show how each one works: