提供纯文本

而不是使用Environmentabstraction(或 YAML 或 properties 格式的替代表示形式之一)时,您的应用程序可能需要针对其环境定制的通用纯文本配置文件。 Config Server 通过位于/{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 参数。 因此,前面的defaultprofile 可以是/sample/default/nginx.conf?useDefaultLabel.

目前,Spring Cloud Config 可以为 git、SVN、原生后端和 AWS S3 提供明文。 对 git、SVN 和原生后端的支持是相同的。AWS S3 的工作方式略有不同。 以下部分显示了每个 API 的工作原理: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.confresource 可能如下所示: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