集成spring clound config时默认情况下,远程配置会覆盖本地配置(除非是命令行参数)。
如果要优先使用本地配置,需要在远程配置中加入一些参数。
spring.cloud.config.allow-override=true(允许被覆盖)
spring.cloud.config.override-none=true (远程配置不覆盖任何本地配置)
spring.cloud.config.override-system-properties=false (远程配置不覆盖系统属性与环境变量,但是会覆盖本地配置文件)
注意:只有设置spring.cloud.config.allow-override=true时,spring.cloud.config.override-none和spring.cloud.config.override-system-properties才会生效。
原文档说明如下:
Overriding the Values of Remote Properties
The property sources that are added to you application by the bootstrap context are often “remote” (e.g. from a Config Server), and by default they cannot be overridden locally, except on the command line. If you want to allow your applications to override the remote properties with their own System properties or config files, the remote property source has to grant it permission by setting spring.cloud.config.allowOverride=true (it doesn’t work to set this locally). Once that flag is set there are some finer grained settings to control the location of the remote properties in relation to System properties and the application’s local configuration: spring.cloud.config.overrideNone=true to override with any local property source, and spring.cloud.config.overrideSystemProperties=false if only System properties and env vars should override the remote settings, but not the local config files.