提供纯文本

与其使用 Environment 抽象(或其在 YAML 或属性格式中的其他替代表示形式),您的应用程序可能需要针对其环境量身定制的通用纯文本配置文件。Config Server 通过一个额外的端点 /{application}/{profile}/{label}/{path} 提供这些文件,其中 applicationprofilelabel 的含义与常规环境端点相同,但 path 是指向文件名的路径(例如 log.xml)。该端点的源文件位置方式与环境端点相同。属性文件和 YAML 文件采用相同的搜索路径。然而,与聚合所有匹配资源不同,此处仅返回第一个匹配的资源。spring-doc.cadn.net.cn

资源定位后,常规格式(${…​})中的占位符将通过所使用的应用名称、配置文件和标签的有效值进行解析。
以此方式,资源端点与环境端点紧密集成。spring-doc.cadn.net.cn

与环境配置的源文件一样,profile 用于解析文件名。因此,如果您想要一个特定于配置文件的文件,/*/development/*/logback.xml 可以通过名为 logback-development.xml 的文件解析(优先于 logback.xml)。
如果您不想提供 label,并让服务器使用默认标签,则可以提供一个 useDefaultLabel 请求参数。因此,前述 default 配置文件的示例可改为 /sample/default/nginx.conf?useDefaultLabel

目前,Spring Cloud Config 可以为 Git、SVN、本地后端以及 AWS S3 提供纯文本内容。Git、SVN 和本地后端的支持方式完全相同;而 AWS S3 的工作方式略有不同。以下各节将分别说明每种方式的工作原理:spring-doc.cadn.net.cn

Git、SVN 和原生后端

考虑以下用于 GIT 或 SVN 仓库或原生后端的示例:spring-doc.cadn.net.cn

application.yml
nginx.conf

代码 nginx.conf 可能类似于以下列表:spring-doc.cadn.net.cn

server {
    listen              80;
    server_name         ${nginx.server.name};
}

application.yml 可能类似于以下列表:spring-doc.cadn.net.cn

nginx:
  server:
    name: example.com
---
spring:
  profiles: development
nginx:
  server:
    name: develop.com

资源 /sample/default/master/nginx.conf 可能如下所示:spring-doc.cadn.net.cn

server {
    listen              80;
    server_name         example.com;
}

/sample/development/master/nginx.conf 可能如下所示:spring-doc.cadn.net.cn

server {
    listen              80;
    server_name         develop.com;
}

AWS S3

为了在 AWS S3 上启用纯文本服务,配置服务器应用程序需要包含对 Spring Cloud AWS 的依赖。有关如何设置该依赖的详细信息,请参阅 Spring Cloud AWS 参考指南。然后,您需要按照 Spring Cloud AWS 参考指南 中所述配置 Spring Cloud AWS。spring-doc.cadn.net.cn

解密明文

默认情况下,纯文本文件中的加密值不会被解密。为了启用对纯文本文件的解密功能,请在 bootstrap.[yml|properties] 中设置 spring.cloud.config.server.encrypt.enabled=truespring.cloud.config.server.encrypt.plainTextEncrypt=truespring-doc.cadn.net.cn

解密纯文本文件仅支持 YAML、JSON 和 properties 文件扩展名。

如果启用了此功能,且请求了不支持的文件扩展名,则文件中的任何加密值将不会被解密。spring-doc.cadn.net.cn