此版本仍在开发中,目前尚不稳定。如需最新稳定版本,请使用 Spring Cloud Config 5.0.1spring-doc.cadn.net.cn

AWS S3 后端

Spring Cloud Config Server 支持 AWS S3 作为配置属性的后端存储。您可以通过添加对 AWS Java SDK for Amazon S3 的依赖来启用此功能。spring-doc.cadn.net.cn

pom.xml
<dependencies>
	<dependency>
		<groupId>software.amazon.awssdk</groupId>
		<artifactId>s3</artifactId>
	</dependency>
</dependencies>

以下配置使用 AWS S3 客户端访问配置文件。我们可使用 spring.cloud.config.server.awss3.* 属性来选择存储配置文件的存储桶。spring-doc.cadn.net.cn

spring:
  profiles:
    active: awss3
  cloud:
    config:
      server:
        awss3:
          region: us-east-1
          bucket: bucket1

还可以指定一个 AWS URL 来 覆盖您 S3 服务的标准端点,方法是使用 spring.cloud.config.server.awss3.endpoint。这使得支持 S3 的测试区域以及其他兼容 S3 的存储 API 成为可能。spring-doc.cadn.net.cn

凭据是通过 默认凭据提供程序链 找到的。无需额外配置即可支持版本化和加密的存储桶。spring-doc.cadn.net.cn

默认情况下,配置文件存储在您的存储桶中,文件名为 {application}-{profile}.properties{application}-{profile}.yml{application}-{profile}.json。可选地,您可以提供一个标签来指定文件的目录路径。spring-doc.cadn.net.cn

当未指定配置文件时,将使用 default

目录结构

Spring Cloud Config Server 还支持与 Git 后端中的 search-paths: '{application}' 类似的按应用目录布局。spring-doc.cadn.net.cn

为了启用它,请将 useDirectoryLayout 属性设置为 true,如下例所示:spring-doc.cadn.net.cn

spring:
  cloud:
    config:
      server:
        awss3:
          region: us-east-1
          bucket: bucket1
          useDirectoryLayout: true

前面的列表匹配存储在您的存储桶中 /{application} 目录下的对象,例如:/{application}/application\{-profile}.yml。此时存储桶的结构应如下所示:spring-doc.cadn.net.cn

├── foo
│   ├── application-test.yml
│   └── application.yml
├── bar
│   ├── application-test.yml
│   └── application.yml