集成spring cloud config后优先使用本地配置

集成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.

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值