资讯

展开

Spring Cloud Config 配置

作者:快盘下载 人气:

Spring Cloud Config 配置

3.1.5

Spring Cloud Config 为分布式系统中的外部化配置提供服务器端和客户端支持。使用配置服务器,您可以在一个中心位置管理所有环境中应用程序的外部属性。 客户端和服务器上的概念与 Springandabstractions 的映射相同,因此它们非常适合 Spring 应用程序,但可以与以任何语言运行的任何应用程序一起使用。 当应用程序通过部署管道从开发到测试再到生产时,可以管理这些环境之间的配置,并确保应用程序在迁移时具有运行所需的一切。 服务器存储后端的默认实现使用 git,因此它可以轻松支持配置环境的标记版本,并可通过各种工具来管理内容。 添加替代实现并使用 Spring 配置插入它们很容易。​​Environment​​​​PropertySource​

快速入门

本快速入门演练如何使用 Spring 云配置服务器的服务器和客户端。

首先,启动服务器,如下所示:

$ cd spring-cloud-config-server
$ ../mvnw spring-boot:run

服务器是一个 Spring 引导应用程序,因此如果您愿意,可以从 IDE 运行它(主类是)。​​ConfigServerApplication​

接下来尝试一个客户端,如下所示:

$ curl localhost:8888/foo/development
{
"name": "foo",
"profiles": [
"development"
]
....
"propertySources": [
{
"name": "https://github.com/spring-cloud-samples/config-repo/foo-development.properties",
"source": {
"bar": "spam",
"foo": "from foo development"
}
},
{
"name": "https://github.com/spring-cloud-samples/config-repo/foo.properties",
"source": {
"foo": "from foo props",
"democonfigclient.message": "hello spring io"
}
},
....

查找属性源的默认策略是克隆 git 存储库 (at) 并使用它来初始化迷你。 迷你应用程序用于枚举属性源并将其发布在 JSON 终结点。​​spring.cloud.config.server.git.uri​​​​SpringApplication​​​​Environment​

HTTP 服务具有以下形式的资源:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

例如:

curl localhost:8888/foo/development
curl localhost:8888/foo/development/master
curl localhost:8888/foo/development,db/master
curl localhost:8888/foo-development.yml
curl localhost:8888/foo-db.properties
curl localhost:8888/master/foo-db.properties

whereis injected as thein the(what is normallyin a regular Spring Boot app),is an active profile (or comma-separated list of properties), andis an optional git label (defaults to.)​​application​​​​spring.config.name​​​​SpringApplication​​​​application​​​​profile​​​​label​​​​master​

Spring 云配置服务器从各种来源提取远程客户端的配置。以下示例从 git 存储库(必须提供)获取配置,如以下示例所示:

spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo

其他来源是任何JDBC兼容数据库,Subversion,Hashicorp Vault,Credhub和本地文件系统。

客户端使用情况

要在应用程序中使用这些功能,您可以将其构建为依赖于 spring-cloud-config-client 的 Spring Boot 应用程序(有关示例,请参阅配置客户端或示例应用程序的测试用例)。 添加依赖项的最方便方法是使用 Spring Boot 启动器。 还有一个用于Maven用户的父pom和BOM(),以及用于Gradle和Spring CLI用户的Spring IO版本管理属性文件。以下示例显示了典型的 Maven 配置:​​org.springFramework.cloud:spring-cloud-starter-config​​​​spring-cloud-starter-parent​

绒球.xml

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>{spring-boot-docs-version}</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>{spring-cloud-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<!-- repositories also needed for snapshots and milestones -->

现在,您可以创建一个标准的 Spring 引导应用程序,例如以下 HTTP 服务器:

@SpringBootApplication
@RestController
public class Application {

@RequestMapping("/")
public String home() {
return "Hello World!";
}

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

}

当此 HTTP 服务器运行时,它会从端口 8888 上的默认本地配置服务器(如果正在运行)获取外部配置。 若要修改启动行为,可以使用以下命令更改配置服务器的位置:​​application.properties​

spring.config.import=optional:configserver:http://myconfigserver.com

默认情况下,如果未设置应用程序名称,将使用。若要修改名称,可以将以下属性添加到文件中:​​application​​​​application.properties​

spring.application.name: myapp

设置属性时不要在应用名称前面加上保留字,以防止在解析正确的属性源时出现问题。​​${spring.application.name}​​​​application-​

配置服务器属性在终结点中显示为高优先级属性源,如以下示例所示。​​/env​

$ curl localhost:8080/env
{
"activeProfiles": [],
{
"name": "servletContextInitParams",
"properties": {}
},
{
"name": "configserver:https://github.com/spring-cloud-samples/config-repo/foo.properties",
"properties": {
"foo": {
"value": "bar",
"origin": "Config Server https://github.com/spring-cloud-samples/config-repo/foo.properties:2:12"
}
}
},
...
}

调用的属性源包含值为 of 的属性。​​configserver:<URL of remote repository>/<file name>​​​​foo​​​​bar​

属性源名称中的 URL 是 git 存储库,而不是配置服务器 URL。

如果使用 Spring Cloud Config Client,则需要设置属性才能绑定到配置服务器。您可以在Spring Cloud Config Reference Guide 中​阅读更多相关信息。​​spring.config.import​

春天云配置服务器

Spring Cloud Config Server 为外部配置(名称-值对或等效的 YAML 内容)提供了一个基于 HTTP 资源的 API。 通过使用注释,服务器可以嵌入到 Spring Boot 应用程序中。 因此,以下应用程序是配置服务器:​​@EnableConfigServer​

配置服务器.java

@SpringBootApplication
@EnableConfigServer
public class ConfigServer {
public static void main(String[] args) {
SpringApplication.run(ConfigServer.class, args);
}
}

像所有 Spring 引导应用程序一样,它默认在端口 8080 上运行,但您可以通过各种方式将其切换到更传统的端口 8888。 最简单的,也设置一个默认的配置存储库,是通过启动它(配置服务器jar中有)。 另一种方法是使用自己的,如以下示例所示:​​spring.config.name=configserver​​​​configserver.yml​​​​application.properties​

应用程序属性

server.port: 8888
spring.cloud.config.server.git.uri: file://${user.home}/config-repo

其中是一个包含 YAML 和属性文件的 git 存储库。​​${user.home}/config-repo​

在 Windows 上,如果文件URL是带有驱动器前缀的绝对值(例如,),则需要在文件URL中增加一个“/”。​​file:///${user.home}/config-repo​


以下清单显示了在前面的示例中创建 git 存储库的配方:




$ cd $HOME
$ mkdir config-repo
$ cd config-repo
$ git init .
$ echo info.foo: bar > application.properties
$ git add -A .
$ git commit -m "Add application.properties"



对 git 存储库使用本地文件系统仅用于测试。 应使用服务器在生产环境中托管配置存储库。

如果仅保留文本文件,则配置存储库的初始克隆可以快速高效。 如果存储二进制文件(尤其是大型文件),则可能会在第一次请求配置时遇到延迟,或者在服务器中遇到内存不足错误。

环境存储库

应将配置服务器的配置数据存储在哪里? 控制此行为的策略是服务对象。 这是来自 Spring 的域的浅层副本(包括作为主要功能)。 其中源由三个变量参数化:​​EnvironmentRepository​​​​Environment​​​​Environment​​​​Environment​​​​propertySources​​​​Environment​

​{application}​​,映射卡通客户端。spring.application.name​{profile}​​,用于映射卡通客户端(逗号分隔的列表)。spring.profiles.active​{label}​​,这是一个服务器端功能,标记一组“版本化”配置文件。

存储库实现通常表现得像 Spring Boot 应用程序,从等于参数和等于参数加载配置文件。 配置文件的优先规则也与常规 Spring 引导应用程序中的优先级规则相同:活动配置文件优先于默认值,如果有多个配置文件,则最后一个配置文件优先(类似于向 a 添加条目)。​​spring.config.name​​​​{application}​​​​spring.profiles.active​​​​{profiles}​​​​Map​

以下示例客户端应用程序具有此引导程序配置:

spring:
application:
name: foo
profiles:
active: dev,mysql

(与 Spring 引导应用程序一样,这些属性也可以通过环境变量或命令行参数设置)。

如果存储库是基于文件的,则服务器将创建 anfrom(在所有客户端之间共享)和(保留优先级)。 如果 YAML 文件中有指向 Spring 配置文件的文档,则以更高的优先级应用这些配置文件(按列出的配置文件顺序)。 如果存在特定于配置文件的 YAML(或属性)文件,则应用这些文件的优先级也高于默认值。 较高的优先级转换为前面的 alist。 (这些相同的规则适用于独立的 Spring 引导应用程序。​​Environment​​​​application.yml​​​​foo.yml​​​​foo.yml​​​​PropertySource​​​​Environment​

您可以将 spring.cloud.config.server.accept-empty 设置为 false,以便在找不到应用程序时服务器将返回 HTTP 404 状态。默认情况下,此标志设置为 true。

Git 后端

默认实现使用 Git 后端,这对于管理升级和物理环境以及审核更改非常方便。 要更改存储库的位置,可以在配置服务器中设置配置属性(例如在中)。 如果使用前缀设置它,它应该从本地存储库工作,以便您可以在没有服务器的情况下快速轻松地开始使用。但是,在这种情况下,服务器直接在本地存储库上运行,而不克隆它(如果它不是裸的并不重要,因为配置服务器从不对“远程”存储库进行更改)。 若要纵向扩展配置服务器并使其高度可用,需要使服务器的所有实例指向同一存储库,以便只有共享文件系统才能工作。 即使在这种情况下,最好将协议用于共享文件系统存储库,以便服务器可以克隆它并使用本地工作副本作为缓存。​​EnvironmentRepository​​​​spring.cloud.config.server.git.uri​​​​application.yml​​​​file:​​​​ssh:​

此存储库实现将 HTTP 资源的参数映射到 git 标签(提交 ID、分支名称或标记)。 如果 git 分支或标签名称包含斜杠 (),则应改为使用 HTTP URL 中的标签指定特殊字符串(以避免与其他 URL 路径产生歧义)。 例如,如果标签是,则替换斜杠将导致以下标签: 包含特殊字符串也可以应用于参数。 如果您使用命令行客户端(如 curl),请注意 URL 中的括号 — 您应该使用单引号 ('') 从 shell 中转义它们。​​{label}​​​​/​​​​(_)​​​​foo/bar​​​​foo(_)bar​​​​(_)​​​​{application}​

跳过 SSL 证书验证

可以通过将属性设置为 (默认值) 来禁用配置服务器对 Git 服务器的 SSL 证书的验证。​​git.skipSslValidation​​​​true​​​​false​

spring:
cloud:
config:
server:
git:
uri: https://example.com/my/repo
skipSslValidation: true
设置 HTTP 连接超时

您可以配置配置服务器等待获取 HTTP 连接的时间(以秒为单位)。使用属性。​​git.timeout​

spring:
cloud:
config:
server:
git:
uri: https://example.com/my/repo
timeout: 4
Git URI 中的占位符

Spring Cloud Config Server 支持带有 theand 占位符的 git 存储库 URL(如果您需要它,但请记住,无论如何标签都是作为 git 标签应用的)。 因此,您可以使用类似于以下内容的结构来支持“每个应用程序一个存储库”策略:​​{application}​​​​{profile}​​​​{label}​

spring:
cloud:
config:
server:
git:
uri: https://github.com/myorg/{application}

您还可以通过使用类似的模式来支持“每个配置文件一个存储库”策略,但与。​​{profile}​

此外,在参数中使用特殊字符串“(_)”可以启用对多个 组织,如以下示例所示:​​{application}​

spring:
cloud:
config:
server:
git:
uri: https://github.com/{application}

其中在请求时以以下格式提供:​​{application}​​​​organization(_)application​

模式匹配和多个存储库

Spring Cloud Config 还包括对更复杂的模式需求的支持 与应用程序和配置文件名称匹配。 模式格式是带有通配符的名称的逗号分隔列表(请注意,以通配符开头的模式可能需要用引号括起来),如以下示例所示:​​{application}/{profile}​

spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
repos:
simple: https://github.com/simple/config-repo
special:
pattern: special*/dev*,*special*/dev*
uri: https://github.com/special/config-repo
local:
pattern: local*
uri: file:/home/configsvc/config-repo

如果与任何模式都不匹配,则使用在下面定义的默认 URI。 在上面的示例中,对于“简单”存储库,模式是(它只匹配所有配置文件中命名的一个应用程序)。“本地”存储库匹配从所有配置文件开始的所有应用程序名称(后缀会自动添加到没有配置文件匹配器的任何模式中)。​​{application}/{profile}​​​​spring.cloud.config.server.git.uri​​​​simple/*​​​​simple​​​​local​​​​/*​

仅当要设置的唯一属性是 URI 时,才能使用“简单”示例中使用的“单行”快捷方式。 如果需要设置其他任何内容(凭据、模式等),则需要使用完整表单。

存储库中的属性实际上是一个数组,因此您可以使用 YAML 数组(属性文件中的后缀等)绑定到多个模式。 如果要运行具有多个配置文件的应用,则可能需要执行此操作,如以下示例所示:​​pattern​​​​[0]​​​​[1]​

spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
repos:
development:
pattern:
- '*/development'
- '*/staging'
uri: https://github.com/development/config-repo
staging:
pattern:
- '*/qa'
- '*/production'
uri: https://github.com/staging/config-repo

Spring Cloud 猜测包含不结束的配置文件的模式暗示您实际上想要匹配以该模式开头的配置文件列表(sois 快捷方式,依此类推)。 例如,当您需要在本地运行“开发”配置文件中但也需要远程运行“云”配置文件中的应用程序时,这很常见。​​*​​​​*/staging​​​​["*/staging", "*/staging,*"]​

每个存储库还可以选择将配置文件存储在子目录中,并且可以指定用于搜索这些目录的模式。 以下示例显示了顶层的配置文件:​​search-paths​

spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
search-paths:
- foo
- bar*

在前面的示例中,服务器在顶级和子目录中搜索配置文件,以及名称以 开头的任何子目录。​​foo/​​​​bar​

默认情况下,服务器在配置时克隆远程存储库 是第一个请求。 可以将服务器配置为在启动时克隆存储库,如以下顶级示例所示:

spring:
cloud:
config:
server:
git:
uri: https://git/common/config-repo.git
repos:
team-a:
pattern: team-a-*
cloneOnStart: true
uri: https://git/team-a/config-repo.git
team-b:
pattern: team-b-*
cloneOnStart: false
uri: https://git/team-b/config-repo.git
team-c:
pattern: team-c-*
uri: https://git/team-a/config-repo.git

在前面的示例中,服务器在启动时克隆 team-a 的配置存储库,在它之前 接受任何请求。 在请求从存储库进行配置之前,不会克隆所有其他存储库。

设置要在配置服务器启动时克隆的存储库有助于在配置服务器启动时快速识别配置错误的配置源(例如无效的存储库 URI)。 如果未为配置源启用,配置服务器可能会使用配置错误或无效的配置源成功启动,并且在应用程序从该配置源请求配置之前不会检测到错误。​​cloneOnStart​

认证

要在远程存储库上使用 HTTP 基本身份验证,请单独添加 and属性(不在 URL 中),如以下示例所示:​​username​​​​password​

spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
username: trolley
password: strongpassword

如果不使用 HTTPS 和用户凭据,则当您将密钥存储在默认目录 () 中并且 URI 指向 SSH 位置(例如)时,SSH 也应该开箱即用。 重要的是,Git 服务器的条目必须存在于文件中,并且它是信息。 不支持其他格式(例如)。 为避免意外,您应该确保 Git 服务器的文件中仅存在一个条目,并且它与您提供给配置服务器的 URL 匹配。 如果在 URL 中使用主机名,则希望在文件中恰好包含该主机名(而不是 IP)。 可以使用 JGit 访问存储库,因此您找到的任何文档都应该适用。 HTTPS 代理设置可以在或(以与任何其他 JVM 进程相同的方式)中设置 系统属性(和)。​​~/.ssh​​​​git@github.com:configuration/cloud-configuration​​​​~/.ssh/known_hosts​​​​ssh-rsa​​​​ecdsa-sha2-nistp256​​​​known_hosts​​​​known_hosts​​​​~/.git/config​​​​-Dhttps.proxyHost​​​​-Dhttps.proxyPort​

如果您不知道您的目录在哪里,请使用来操作设置(例如,)。​​~/.git​​​​git config --global​​​​git config --global http.sslVerify false​

JGit 需要 PEM 格式的 RSA 密钥。下面是一个示例 ssh-keygen(来自 openssh)命令,它将生成一个 corect 格式的密钥:

ssh-keygen -m PEM -t rsa -b 4096 -f ~/config_server_deploy_key.rsa

警告:使用 SSH 密钥时,预期的 ssh 私钥必须以 开头。如果密钥以 开头,则在启动 spring-cloud-config 服务器时,RSA 密钥将不会加载。错误如下所示:​​-----BEGIN RSA PRIVATE KEY-----​​​​-----BEGIN OPENSSH PRIVATE KEY-----​

- Error in object 'spring.cloud.config.server.git': codes [PrivateKeyIsValid.spring.cloud.config.server.git,PrivateKeyIsValid]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [spring.cloud.config.server.git.,]; arguments []; default message []]; default message [Property 'spring.cloud.config.server.git.privateKey' is not a valid private key]

要更正上述错误,必须将 RSA 密钥转换为 PEM 格式。上面提供了一个使用 openssh 的示例,用于以适当的格式生成新密钥。

使用 AWS CodeCommit 进行身份验证

Spring Cloud Config Server 还支持AWS CodeCommit身份验证。 AWS CodeCommit 在命令行使用 Git 时使用身份验证帮助程序。 此帮助程序不与 JGit 库一起使用,因此如果 Git URI 与 AWS CodeCommit 模式匹配,则会创建适用于 AWS CodeCommit 的 JGit 凭证提供程序。 AWS CodeCommit URI 遵循以下模式:

https//git-codecommit.${AWS_REGION}.amazonaws.com/v1/repos/${repo}.

如果您提供带有 AWS CodeCommit URI 的用户名和密码,则它们必须是提供对存储库的访问权限的AWS accessKeyId 和 secretAccessKey。 如果您未指定用户名和密码,则会使用AWS 默认凭证提供程序链检索访问密钥 ID 和 secretAccessKey。

如果您的 Git URI 与 CodeCommit URI 模式(如前所示)匹配,则必须在用户名和密码中或在默认凭证提供程序链支持的位置之一中提供有效的 AWS 凭证。 AWS EC2 实例可以使用适用于 EC2 实例的 IAM 角色。

Thejar 是一个可选的依赖项。 如果 jar 不在您的类路径中,则无论 git 服务器 URI 如何,都不会创建 AWS 代码提交凭证提供程序。​​aws-java-sdk-core​​​​aws-java-sdk-core​

使用谷歌云源进行身份验证

Spring Cloud Config Server 还支持针对Google Cloud Source存储库进行身份验证。

如果您的 Git URI 使用理论协议,而域名是,则将使用 Google Cloud Source 凭据提供程序。Google Cloud Source 存储库 URI 具有该格式。要获取存储库的 URI,请单击 Google 云源界面中的“克隆”,然后选择“手动生成的凭据”。不要生成任何凭据,只需复制显示的 URI。​​http​​​​https​​​​source.developers.google.com​​​​https://source.developers.google.com/p/${GCP_PROJECT}/r/${REPO}​

Google Cloud Source 凭据提供程序将使用 Google Cloud Platform 应用程序默认凭据。请参阅Google Cloud SDK 文档,了解如何为系统创建应用默认凭据。此方法适用于开发环境中的用户帐户和生产环境中的服务帐户。

​com.google.auth:google-auth-library-oauth2-http​​​是可选的依赖项。 如果 thejar 不在您的类路径中,则无论 git 服务器 URI 如何,都不会创建 Google Cloud Source 凭据提供程序。​​google-auth-library-oauth2-http​

使用属性的 Git SSH 配置

默认情况下,Spring Cloud Config Server 使用的 JGit 库使用 SSH 配置文件,例如使用 SSH URI 连接到 Git 存储库时。 在Cloud Foundry等云环境中,本地文件系统可能是短暂的或不容易访问的。 对于这些情况,可以使用 Java 属性设置 SSH 配置。 为了激活基于属性的 SSH 配置,必须将属性设置为,如以下示例所示:​​~/.ssh/known_hosts​​​​/etc/ssh/ssh_config​​​​spring.cloud.config.server.git.ignoreLocalSshSettings​​​​true​

spring:
cloud:
config:
server:
git:
uri: git@gitserver.com:team/repo1.git
ignoreLocalSshSettings: true
hostKey: someHostKey
hostKeyAlgorithm: ssh-rsa
privateKey: |
-----BEGIN RSA PRIVATE KEY-----
MIIEpgIBAAKCAQEAx4UbaDzY5xjW6hc9jwN0mX33XpTDVW9WqHp5AKaRbtAC3DqX
IXFMPgw3K45jxRb93f8tv9vL3rD9CUG1Gv4FM+o7ds7FRES5RTjv2RT/JVNJCoqF
ol8+ngLqRZCyBtQN7zYByWMRirPGoDUqdPYrj2yq+ObBBNhg5N+hOwKjjpzdj2Ud
1l7R+wxIqmJo1IYyy16xS8WsjyQuyC0lL456qkd5BDZ0Ag8j2X9H9D5220Ln7s9i
oezTipXipS7p7Jekf3Ywx6abJwOmB0rX79dV4qiNcGgzATnG1PkXxqt76VhcGa0W
DDVHEEYGbSQ6hIGSh0I7BQun0aLRZojfE3gqHQIDAQABAoIBAQCZmGrk8BK6tXCd
fY6yTiKxFzwb38IQP0ojIUWNrq0+9Xt+NsypviLHkXfXXCKKU4zUHeIGVRq5MN9b
BO56/RrcQHHOoJdUWuOV2qMqJvPUtC0CpGkD+valhfD75MxoXU7s3FK7yjxy3rsG
EmfA6tHV8/4a5umo5TqSd2YTm5B19AhRqiuUVI1wTB41DjULUGiMYrnYrhzQlVvj
5MjnKTlYu3V8PoYDfv1GmxPPh6vlpafXEeEYN8VB97e5x3DGHjZ5UrurAmTLTdO8
+AahyoKsIY612TkkQthJlt7FJAwnCGMgY6podzzvzICLFmmTXYiZ/28I4BX/mOSe
pZVnfRixAoGBAO6Uiwt40/PKs53mCEWngslSCsh9oGAaLTf/XdvMns5VmuyyAyKG
ti8Ol5wqBMi4GIUzjbgUvSUt+IowIrG3f5tN85wpjQ1UGVcpTnl5Qo9xaS1PFScQ
xrtWZ9eNj2TsIAMp/svJsyGG3OibxfnuAIpSXNQiJPwRlW3irzpGgVx/AoGBANYW
dnhshUcEHMJi3aXwR12OTDnaLoanVGLwLnkqLSYUZA7ZegpKq90UAuBdcEfgdpyi
PhKpeaeIiAaNnFo8m9aoTKr+7I6/uMTlwrVnfrsVTZv3orxjwQV20YIBCVRKD1uX
VhE0ozPZxwwKSPAFocpyWpGHGreGF1AIYBE9UBtjAoGBAI8bfPgJpyFyMiGBjO6z
FwlJc/xlFqDusrcHL7abW5QQ0L4v3R+FrJw3ZYufzLTVcKfdj6GelwJJO+8wBm+R
gTKYJItEhT48duLIfTDyIpHGVm9+I1MGhh5zKuCqIhxIYr9jHloBB7kRm0rPvYY4
VAykcNgyDvtAVODP+4m6JvhjAoGBALbtTqErKN47V0+JJpapLnF0KxGrqeGIjIRV
cYA6V4WYGr7NeIfesecfOC356PyhgPfpcVyEztwlvwTKb3RzIT1TZN8fH4YBr6Ee
KTbTjefRFhVUjQqnucAvfGi29f+9oE3Ei9f7wA+H35ocF6JvTYUsHNMIO/3gZ38N
CPjyCMa9AoGBAMhsITNe3QcbsXAbdUR00dDsIFVROzyFJ2m40i4KCRM35bC/BIBs
q0TY3we+ERB40U8Z2BvU61QuwaunJ2+uGadHo58VSVdggqAo0BSkH58innKKt96J
69pcVH/4rmLbXdcmNYGm6iu+MlPQk4BUZknHSmVHIFdJ0EPupVaQ8RHT
-----END RSA PRIVATE KEY-----

下表描述了 SSH 配置属性。

Table 1. SSH Configuration Properties

属性名称

言论

忽略本地Ssh设置

如果,请使用基于属性的 SSH 配置,而不是基于文件的 SSH 配置。必须设置为 as,而不是在存储库定义中。​​true​​​​spring.cloud.config.server.git.ignoreLocalSshSettings​

私钥

有效的 SSH 私钥。必须设置为 ifis true,Git URI 为 SSH 格式。​​ignoreLocalSshSettings​

主机密钥

有效的 SSH 主机密钥。必须设置 ifis 也设置。​​hostKeyAlgorithm​

主机密钥算法

之一。必须设置 ifis 也设置。​​ssh-dss, ssh-rsa, ssh-ed25519, ecdsa-sha2-nistp256, ecdsa-sha2-nistp384, or ecdsa-sha2-nistp521​​​​hostKey​

严格主机密钥检查

​true​​​或。如果为 false,则忽略主机密钥的错误。​​false​

已知主机文件

自定义文件的位置。​​.known_hosts​

首选身份验证

覆盖服务器身份验证方法顺序。如果服务器在方法之前具有键盘交互式身份验证,这应该允许规避登录提示。​​publickey​

Git 搜索路径中的占位符

Spring Cloud Config Server 还支持带有占位符的搜索路径,用于 theand(andif 您需要它),如以下示例所示:​​{application}​​​​{profile}​​​​{label}​

spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
search-paths: '{application}'

前面的清单导致在存储库中搜索与目录(以及顶级)同名的文件。 通配符在带有占位符的搜索路径中也有效(任何匹配的目录都包含在搜索中)。

强制拉取 Git 存储库

如前所述,Spring Cloud Config Server 会克隆远程 git 存储库,以防本地副本变脏(例如, 文件夹内容由操作系统进程更改),以便 Spring 云配置服务器无法从远程存储库更新本地副本。

为了解决这个问题,如果本地副本脏了,则有一个属性可以使 Spring 云配置服务器强制从远程存储库拉取,如以下示例所示:​​force-pull​

spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
force-pull: true

如果您有多存储库配置,则可以配置每个存储库的属性,如以下示例所示:​​force-pull​

spring:
cloud:
config:
server:
git:
uri: https://git/common/config-repo.git
force-pull: true
repos:
team-a:
pattern: team-a-*
uri: https://git/team-a/config-repo.git
force-pull: true
team-b:
pattern: team-b-*
uri: https://git/team-b/config-repo.git
force-pull: true
team-c:
pattern: team-c-*
uri: https://git/team-a/config-repo.git

属性的默认值为。​​force-pull​​​​false​

删除 Git 存储库中未跟踪的分支

由于 Spring 云配置服务器具有远程 git 存储库的克隆 将分支签出到本地存储库(例如按标签获取属性)后,它将保留此分支 永远或直到下一次服务器重新启动(创建新的本地存储库)。 因此,可能会出现删除远程分支但仍然可以获取的本地副本的情况。 如果 Spring 云配置服务器客户端服务以 它开始,它将从本地分支获取属性,但不会从。​​--spring.cloud.config.label=deletedRemoteBranch,master​​​​deletedRemoteBranch​​​​master​

为了保持本地存储库分支的清洁,可以设置远程属性。 它将使 Spring 云配置服务器强制从本地存储库中删除未跟踪的分支。 例:​​deleteUntrackedBranches​

spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
deleteUntrackedBranches: true

属性的默认值为。​​deleteUntrackedBranches​​​​false​

Git 刷新率

您可以控制配置服务器获取更新的配置数据的频率 从 Git 后端使用。这 此属性的值以秒为单位指定。默认情况下,该值为 0,这意味着 配置服务器每次都会从 Git 存储库获取更新的配置 是请求的。​​spring.cloud.config.server.git.refreshRate​

默认标签

用于 Git 的默认标签是。如果您没有设置并且名为 name 的分支不存在,则默认情况下配置服务器也会尝试签出名为的分支。如果 您希望禁用可以设置为的回退分支行为。​​main​​​​spring.cloud.config.server.git.defaultLabel​​​​main​​​​master​​​​spring.cloud.config.server.git.tryMasterBranch​​​​false​

版本控制后端文件系统使用

使用基于 VCS 的后端(git、svn),文件被签出或克隆到本地文件系统。 默认情况下,它们放在前缀为 of 的系统临时目录中。 例如,在Linux上,它可能是。 某些操作系统会定期清理​临时目录。 这可能会导致意外行为,例如缺少属性。 若要避免此问题,请通过设置或将配置服务器使用的目录更改为不驻留在系统临时结构中的目录。​​config-repo-​​​​/tmp/config-repo-<randomid>​​​​spring.cloud.config.server.git.basedir​​​​spring.cloud.config.server.svn.basedir​

文件系统后端

配置服务器中还有一个“本机”配置文件,它不使用 Git,而是从本地类路径或文件系统(要指向的任何静态 URL)加载配置文件。 要使用本机配置文件,请启动配置服务器。​​spring.cloud.config.server.native.searchLocations​​​​spring.profiles.active=native​

请记住对文件资源使用前缀(不带前缀的默认值通常是类路径)。 与任何 Spring 引导配置一样,您可以嵌入样式的环境占位符,但请记住,Windows 中的绝对路径需要额外的(例如,)。​​file:​​​​${}​​​​/​​​​file:///${user.home}/config-repo​

的默认值与本地 Spring 引导应用程序相同(即)。 这不会向所有客户端公开从服务器,因为服务器中存在的任何属性源在发送到客户端之前都会被删除。​​searchLocations​​​​[classpath:/, classpath:/config, file:./, file:./config]​​​​application.properties​

文件系统后端非常适合快速入门和测试。 要在生产中使用它,您需要确保文件系统是可靠的,并且在配置服务器的所有实例之间共享。

搜索位置可以包含 、 和 的占位符。 通过这种方式,您可以隔离路径中的目录并选择对您有意义的策略(例如每个应用程序的子目录或每个配置文件的子目录)。​​{application}​​​​{profile}​​​​{label}​

如果不在搜索位置中使用占位符,则此存储库还会将 HTTP 资源的参数附加到搜索路径上的后缀,以便从每个搜索位置和与标签同名的子目录加载属性文件(标记的属性在 Spring 环境中优先)。 因此,没有占位符的默认行为与添加以 结尾的搜索位置相同。 例如,与 相同。 可以通过设置禁用此行为。​​{label}​​​​/{label}/​​​​file:/tmp/config​​​​file:/tmp/config,file:/tmp/config/{label}​​​​spring.cloud.config.server.native.addLabelLocations=false​

保管库后端

Spring Cloud Config Server还支持Vault作为后端。

保险柜是一种用于安全访问机密的工具。 机密是要严格控制访问的任何内容,例如 API 密钥、密码、证书和其他敏感信息。Vault 为任何机密提供统一的界面,同时提供严格的访问控制并记录详细的审核日志。

有关保险柜的更多信息,请参阅保险柜快速入门指南。

要使配置服务器能够使用 Vault 后端,您可以使用配置文件运行配置服务器。 例如,在您的配置服务器中,您可以添加。​​vault​​​​application.properties​​​​spring.profiles.active=vault​

默认情况下,Spring Cloud Config Server 使用基于令牌的身份验证从 Vault 获取配置。 Vault还支持其他身份验证方法,如AppRole,LDAP,JWT,CloudFoundry,Kubernetes Auth。 为了使用除 TOKEN 或 X-Config-Token 标头之外的任何身份验证方法,我们需要在类路径上安装 Spring Vault Core,以便配置服务器可以将身份验证委托给该库。请将以下依赖项添加到配置服务器应用。

​Maven (pom.xml)​

<dependencies>
<dependency>
<groupId>org.springframework.vault</groupId>
<artifactId>spring-vault-core</artifactId>
</dependency>
</dependencies>

​Gradle (build.gradle)​

dependencies {
implementation "org.springframework.vault:spring-vault-core"
}

默认情况下,配置服务器假定您的 Vault 服务器运行在 。 它还假定后端的名称是和密钥是。 所有这些默认值都可以在配置服务器中配置。 下表描述了可配置的 Vault 属性:​​http://127.0.0.1:8200​​​​secret​​​​application​​​​application.properties​

名字

默认值

主机

127.0.0.1

港口

8200

方案

http

后端

秘密

默认键

应用

配置文件分隔符

,

千伏版本

1

skipSslValidation

超时

5

命名空间

上表中的所有属性都必须带有前缀或放置在复合配置的正确 Vault 部分中。​​spring.cloud.config.server.vault​

所有可配置的属性都可以在中找到。​​org.springframework.cloud.config.server.environment.VaultEnvironmentProperties​

Vault 0.10.0 引入了一个版本化的键值后端(k/v 后端版本 2),它公开了与早期版本不同的 API,它现在需要在挂载路径和实际上下文路径之间,并将机密包装在对象中。设置将考虑到这一点。​​data/​​​​data​​​​spring.cloud.config.server.vault.kv-version=2​

(可选)支持保管库企业标头。要将其发送到保险柜设置属性。​​X-Vault-Namespace​​​​namespace​

在配置服务器运行时,您可以向服务器发出 HTTP 请求以检索 保管库后端的值。 为此,您需要为 Vault 服务器提供令牌。

首先,将一些数据放入保险柜中,如以下示例所示:

$ vault kv put secret/application foo=bar baz=bam
$ vault kv put secret/myapp foo=myappsbar

其次,向配置服务器发出 HTTP 请求以检索值,如以下示例所示:

​$ curl -X "GET" "http://localhost:8888/myapp/default" -H "X-Config-Token: yourtoken"​

您应该看到类似于以下内容的响应:

{
"name":"myapp",
"profiles":[
"default"
],
"label":null,
"version":null,
"state":null,
"propertySources":[
{
"name":"vault:myapp",
"source":{
"foo":"myappsbar"
}
},
{
"name":"vault:application",
"source":{
"baz":"bam",
"foo":"bar"
}
}
]
}

客户端提供必要的身份验证以允许配置服务器与 Vault 通信的默认方法是设置 X-Config-Token 标头。 但是,您可以通过设置与 Spring Cloud Vault 相同的配置属性来省略标头并在服务器中配置身份验证。 要设置的属性是。 应将其设置为受支持的身份验证方法之一。 您可能还需要设置特定于您使用的身份验证方法的其他属性,方法是使用与 for for 记录的相同的属性名称,而不是使用前缀。 有关更多详细信息,请参阅Spring 云保管库参考指南。​​spring.cloud.config.server.vault.authentication​​​​spring.cloud.vault​​​​spring.cloud.config.server.vault​

如果省略 X-Config-Token 标头并使用服务器属性来设置身份验证,则配置服务器应用程序需要对 Spring Vault 的额外依赖才能启用其他身份验证选项。 请参阅Spring Vault 参考指南,了解如何添加该依赖项。

多个属性源

使用 Vault 时,您可以为应用程序提供多个属性源。 例如,假设您已将数据写入保险柜中的以下路径:

secret/myApp,dev
secret/myApp
secret/application,dev
secret/application

写入的属性可用于使用配置服务器的所有应用程序。 具有名称 ,的应用程序将写入任何属性并可供其使用。 启用配置文件后,写入上述所有路径的属性将可供它使用,列表中第一个路径中的属性优先于其他路径。​​secret/application​​​​myApp​​​​secret/myApp​​​​secret/application​​​​myApp​​​​dev​

通过代理访问后端

配置服务器可以通过 HTTP 或 HTTPS 代理访问 Git 或保管库后端。 对于 Git 或保管库,此行为由 under 和 下的设置控制。 这些设置是按存储库进行的,因此,如果您使用的是复合环境存储库,则必须为复合环境存储库中的每个后端单独配置代理设置。 如果使用的网络需要为 HTTP 和 HTTPS URL 提供单独的代理服务器,则可以为单个后端配置 HTTP 和 HTTPS 代理设置:在这种情况下,访问将使用代理并访问一个。 此外,您可以使用应用程序和代理之间的代理定义协议指定一个将用于两个协议的唯一代理。​​proxy.http​​​​proxy.https​​​​http​​​​http​​​​https​​​​https​

下表描述了 HTTP 和 HTTPS 代理的代理配置属性。所有这些属性都必须以 by or 为前缀。​​proxy.http​​​​proxy.https​

Table 2. Proxy Configuration Properties

属性名称

言论

主机

代理的主机。

港口

用于访问代理的端口。

非代理主机

配置服务器应在代理外部访问的任何主机。如果为两者提供了值,则将使用该值。​​proxy.http.nonProxyHosts​​​​proxy.https.nonProxyHosts​​​​proxy.http​

用户名

用于向代理进行身份验证的用户名。如果为两者提供了值,则将使用该值。​​proxy.http.username​​​​proxy.https.username​​​​proxy.http​

密码

用于向代理进行身份验证的密码。如果为两者提供了值,则将使用该值。​​proxy.http.password​​​​proxy.https.password​​​​proxy.http​

以下配置使用 HTTPS 代理访问 Git 存储库。

spring:
profiles:
active: git
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
proxy:
https:
host: my-proxy.host.io
password: myproxypassword
port: '3128'
username: myproxyusername
nonProxyHosts: example.com

与所有应用程序共享配置

在所有应用程序之间共享配置因采用的方法而异,如以下主题中所述:

基于文件的存储库库服务器
基于文件的存储库

使用基于文件(git、svn 和本机)存储库,文件名为 in(,,, 等)的资源在所有客户端应用程序之间共享。 您可以使用具有这些文件名的资源来配置全局默认值,并根据需要由特定于应用程序的文件覆盖它们。​​application*​​​​application.properties​​​​application.yml​​​​application-*.properties​

属性覆盖功能还可用于设置全局默认值,以及占位符应用程序 允许在本地覆盖它们。

对于“本机”配置文件(本地文件系统后端),您应该使用不属于服务器自身配置的显式搜索位置。 否则,默认搜索位置中的资源将被删除,因为它们是服务器的一部分。​​application*​

库服务器

使用 Vault 作为后端时,您可以通过放置配置与所有应用程序共享配置。 例如,如果运行以下 Vault 命令,则使用配置服务器的所有应用程序都将具有以下属性并且可供它们使用:​​secret/application​​​​foo​​​​baz​

$ vault write secret/application foo=bar baz=bam
CredHub服务器

使用 CredHub 作为后端时,您可以通过将配置放入或将其放置在应用程序的配置文件中来与所有应用程序共享配置。 例如,如果运行以下 CredHub 命令,则使用配置服务器的所有应用程序都将具有属性并且可供它们使用:​​/application/​​​​default​​​​shared.color1​​​​shared.color2​

credhub set --name "/application/profile/master/shared" --type=json
value: {"shared.color1": "blue", "shared.color": "red"}
credhub set --name "/my-app/default/master/more-shared" --type=json
value: {"shared.word1": "hello", "shared.word2": "world"}

AWS 密钥管理器

使用 AWS Secrets Manager 作为后端时,您可以通过将配置放入或将配置放置在应用程序的配置文件中来与所有应用程序共享配置。 例如,如果使用以下键添加机密,则使用配置服务器的所有应用程序都将具有属性并且可供它们使用:​​/application/​​​​default​​​​shared.foo​​​​shared.bar​

secret name = /secret/application-default/
secret value =
{
shared.foo: foo,
shared.bar: bar
}

secret name = /secret/application/
secret value =
{
shared.foo: foo,
shared.bar: bar
}
AWS 参数存储

使用 AWS 参数存储作为后端时,您可以通过将属性放置在层次结构中来与所有应用程序共享配置。​​/application​

例如,如果添加具有以下名称的参数,则使用配置服务器的所有应用程序都将具有属性并且可供它们使用:​​foo.bar​​​​fred.baz​

/config/application/foo.bar
/config/application-default/fred.baz

JDBC 后端

Spring Cloud Config Server 支持 JDBC(关系数据库)作为配置属性的后端。 可以通过添加到类路径并使用配置文件或添加类型的 Bean 来启用此功能。 如果在类路径中包含正确的依赖项(有关更多详细信息,请参阅用户指南),Spring Boot 将配置数据源。​​spring-jdbc​​​​jdbc​​​​JdbcEnvironmentRepository​

您可以通过将属性设置为来禁用自动配置。​​JdbcEnvironmentRepository​​​​spring.cloud.config.server.jdbc.enabled​​​​false​

数据库需要有一个表,称为 列 调用,和(通常的意思),加号和 for 样式中的键值对。 在 Java 中,所有字段都是字符串类型,因此您可以使它们具有所需的任何长度。 属性值的行为方式与它们来自命名的 Spring Boot 属性文件(包括所有加密和解密)的行为方式相同,这些文件将作为后处理步骤应用(即,不直接在存储库实现中)。​​PROPERTIES​​​​APPLICATION​​​​PROFILE​​​​LABEL​​​​Environment​​​​KEY​​​​VALUE​​​​Properties​​​​VARCHAR​​​​{application}-{profile}.properties​

瑞迪斯后端

Spring Cloud Config Server 支持 redis 作为配置属性的后端。 您可以通过向Spring Data Redis添加依赖项来启用此功能。

绒球.xml

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies>

以下配置使用 Spring 数据来访问 Redis。我们可以使用属性来覆盖默认连接设置。​​RedisTemplate​​​​spring.redis.*​

spring:
profiles:
active: redis
redis:
host: redis
port: 16379

属性应作为字段存储在哈希中。哈希的名称应与 and 的属性或连词相同。​​spring.application.name​​​​spring.application.name​​​​spring.profiles.active[n]​

HMSET sample-app server.port "8100" sample.topic.name "test" test.property1 "property1"

运行在哈希上方可见的命令后,哈希应包含以下带有值的键:

HGETALL sample-app
{
"server.port": "8100",
"sample.topic.name": "test",
"test.property1": "property1"
}

未指定配置文件时将使用。​​default​

AWS S3 后端

Spring Cloud Config Server 支持 AWS S3 作为配置属性的后端。 您可以通过向适用于 Amazon S3 的 AWS Java 开发工具包添加依赖项来启用此功能。

绒球.xml

<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
</dependency>
</dependencies>

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

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

还可以指定 AWS URL 以覆盖 S3 服务的标准终端节点。这允许支持 S3 的测试区域和其他与 S3 兼容的存储 API。​​spring.cloud.config.server.awss3.endpoint​

凭证是使用默认 AWS 凭证提供程序链找到的。支持版本控制和加密存储桶,无需进一步配置。

配置文件存储在存储桶中,作为,或。可以提供可选标签来指定文件的目录路径。​​{application}-{profile}.properties​​​​{application}-{profile}.yml​​​​{application}-{profile}.json​

未指定配置文件时将使用。​​default​

AWS 参数存储后端

Spring Cloud Config Server 支持 AWS Parameter Store 作为配置属性的后端。您可以通过向适用于 SSM 的 AWS Java 开发工具包添加依赖项来启用此功能。

绒球.xml

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ssm</artifactId>
</dependency>

以下配置使用 AWS SSM 客户端访问参数。

spring:
profiles:
active: awsparamstore
cloud:
config:
server:
awsparamstore:
region: eu-west-2
endpoint: https://ssm.eu-west-2.amazonaws.com
origin: aws:parameter:
prefix: /config/service
profile-separator: _
recursive: true
decrypt-values: true
max-results: 5

下表描述了 AWS 参数存储配置属性。

Table 3. AWS Parameter Store Configuration Properties

属性名称

必填

默认值

言论

地区

AWS 参数存储客户端要使用的区域。如果未显式设置,SDK 会尝试使用默认区域提供程序链确定要使用的区域。

端点

AWS SSM 客户端入口点的 URL。这可用于为 API 请求指定备用终端节点。

起源

​aws:ssm:parameter:​

添加到属性源名称以显示其来源的前缀。

前缀

​/config​

前缀,指示从 AWS 参数存储加载的每个属性的参数层次结构中的 L1 级别。

配置文件分隔符

​-​

将追加的配置文件与上下文名称分开的字符串。

递归的

​true​

指示检索层次结构中所有 AWS 参数的标志。

解密值

​true​

指示检索所有 AWS 参数并解密其值的标志。

最大结果

​10​

要为 AWS 参数存储 API 调用返回的最大项目数。

AWS 参数存储 API 凭证是使用默认凭证提供程序链确定的。 版本化参数已通过返回最新版本的默认行为得到支持。


未指定应用程序时是默认值,未指定配置文件时使用。​​application​​​​default​​的有效值必须以正斜杠开头,后跟一个或多个有效路径段,否则为空。​​awsparamstore.prefix​​有效值只能包含点、短划线和下划线。​​awsparamstore.profile-separator​​的有效值必须在[1, 10]范围内。​​awsparamstore.max-results​


AWS 密钥管理器后端

Spring Cloud Config Server 支持AWS Secrets Manager作为配置属性的后端。 您可以通过向适用于密钥管理器的 AWS Java 开发工具包添加依赖项来启用此功能。

绒球.xml

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-secretsmanager</artifactId>
</dependency>

以下配置使用 AWS 密钥管理器客户端访问密钥。

spring:
profiles:
active: awssecretsmanager
cloud:
config:
server:
aws-secretsmanager:
region: us-east-1
endpoint: https://us-east-1.console.aws.amazon.com/
origin: aws:secrets:
prefix: /secret/foo
profileSeparator: _

AWS Secrets Manager API 凭证是使用默认凭证提供程序链确定的。


未指定应用程序时是默认值,未指定配置文件时使用。​​application​​​​default​


CredHub 后端

Spring Cloud Config Server支持CredHub作为配置属性的后端。 您可以通过向Spring CredHub添加依赖项来启用此功能。

绒球.xml

<dependencies>
<dependency>
<groupId>org.springframework.credhub</groupId>
<artifactId>spring-credhub-starter</artifactId>
</dependency>
</dependencies>

以下配置使用双向 TLS 访问 CredHub:

spring:
profiles:
active: credhub
cloud:
config:
server:
credhub:
url: https://credhub:8844

属性应存储为 JSON,例如:

credhub set --name "/demo-app/default/master/toggles" --type=json
value: {"toggle.button": "blue", "toggle.link": "red"}
credhub set --name "/demo-app/default/master/abs" --type=json
value: {"marketing.enabled": true, "external.enabled": false}

具有该名称的所有客户端应用程序将具有以下可用属性:​​spring.cloud.config.name=demo-app​

{
toggle.button: "blue",
toggle.link: "red",
marketing.enabled: true,
external.enabled: false
}

未指定配置文件时将使用配置文件,未指定标签时将用作默认值。 注意:添加到的值将由所有应用程序共享。​​default​​​​master​​​​application​

OAuth 2.0

您可以使用UAA作为提供程序通过OAuth 2.0进行身份验证。

绒球.xml

<dependencies>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
</dependency>
</dependencies>

以下配置使用 OAuth 2.0 和 UAA 访问 CredHub:

spring:
profiles:
active: credhub
cloud:
config:
server:
credhub:
url: https://credhub:8844
oauth2:
registration-id: credhub-client
security:
oauth2:
client:
registration:
credhub-client:
provider: uaa
client-id: credhub_config_server
client-secret: asecret
authorization-grant-type: client_credentials
provider:
uaa:
token-uri: https://uaa:8443/oauth/token

使用的 UAA 客户端 ID 应具有作用域。​​credhub.read​

加载全部内容

相关教程
猜你喜欢
用户评论
快盘暂不提供评论功能!