Property Overrides
配置服务器有一个“overrides
”功能,允许操作员向所有应用程序提供配置属性。应用程序不能通过正常的 Spring Boot 挂钩意外更改被覆盖的属性。若要声明覆盖项,请向 spring.cloud.config.server.overrides
添加一个键值对映射,如下例所示:
The Config Server has an “overrides” feature that lets the operator provide configuration properties to all applications.
The overridden properties cannot be accidentally changed by the application with the normal Spring Boot hooks.
To declare overrides, add a map of name-value pairs to spring.cloud.config.server.overrides
, as shown in the following example:
spring:
cloud:
config:
server:
overrides:
foo: bar
前面的示例导致所有作为配置客户端的应用程序都将读取 foo=bar
,而与它们自己的配置无关。
The preceding examples causes all applications that are config clients to read foo=bar
, independent of their own configuration.
配置系统无法强制应用程序以任何特定方式使用配置数据。因此,并不强制执行覆盖。但是,它们确实为 Spring Cloud Config 客户端提供了有用的默认行为。 |
A configuration system cannot force an application to use configuration data in any particular way. Consequently, overrides are not enforceable. However, they do provide useful default behavior for Spring Cloud Config clients. |
通常情况下,带 |
Normally, Spring environment placeholders with |
在 YAML 中,您不需要转义反斜杠本身。但是,在属性文件中,当您在服务器上配置覆盖时,您确实需要转义反斜杠。 |
In YAML, you do not need to escape the backslash itself. However, in properties files, you do need to escape the backslash, when you configure the overrides on the server. |
通过在远程仓库中设置 spring.cloud.config.overrideNone=true
标志(默认值为 false),可以更改客户端中所有覆盖的优先级,使其更接近默认值,允许应用程序在环境变量或系统属性中提供自己的值。
You can change the priority of all overrides in the client to be more like default values, letting applications supply their own values in environment variables or System properties, by setting the spring.cloud.config.overrideNone=true
flag (the default is false) in the remote repository.