提供纯文本

而不是使用Environment抽象(或 YAML 或属性格式的替代表示形式之一),应用程序可能需要针对其环境定制的通用纯文本配置文件。 配置服务器通过位于/{application}/{profile}/{label}/{path}哪里application,profilelabel与常规环境端点具有相同的含义,但path是文件名的路径(例如log.xml). 此端点的源文件的位置与环境端点的源文件相同。 属性和 YAML 文件使用相同的搜索路径。 但是,不会聚合所有匹配的资源,而是仅返回第一个匹配的资源。spring-doc.cadn.net.cn

找到资源后,正常格式的占位符 (${…​})通过使用有效的Environment用于提供的应用程序名称、配置文件和标签。 这样,资源端点与环境端点紧密集成。spring-doc.cadn.net.cn

与环境配置的源文件一样,profile用于解析文件名。 因此,如果您想要一个特定于配置文件的文件,/*/development/*/logback.xml可以通过名为logback-development.xml(优先于logback.xml).
如果您不想提供label并让服务器使用默认标签,你可以提供一个useDefaultLabelrequest 参数。 因此,前面的示例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 启用纯文本服务,Config Server 应用程序需要包含对 Spring Cloud AWS 的依赖项。 有关如何设置该依赖项的详细信息,请参阅 Spring Cloud AWS 参考指南。 然后,您需要配置 Spring Cloud AWS,如 Spring Cloud AWS 参考指南中所述。spring-doc.cadn.net.cn

解密纯文本

默认情况下,不会解密纯文本文件中的加密值。要启用纯文本文件的解密,请将spring.cloud.config.server.encrypt.enabled=truespring.cloud.config.server.encrypt.plainTextEncrypt=truebootstrap.[yml|properties]spring-doc.cadn.net.cn

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

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