How spring cloud config use local property override remote property
Asked Answered
K

4

25

I know should set following properties, but still confused about where they should be set.

spring:
    cloud:
        config:
            allowOverride: true
            failFast: true
            overrideNone: false

application.properties file on spring cloud server side or client side or remote git repository?

I set them in application.yml on server side, but don't work.

I try set in application.yml on remote git, and again not work, hope you could give me some help, thanks.

Kif answered 5/5, 2017 at 8:37 Comment(2)
Set it in bootstrap.yml in your spring-boot application.Worsen
@Worsen Thank you for your answer, but still have a question. Which spring-boot application should bootstrap.yml be in, spring cloud client or spring cloud server?Kif
K
23

I set the following configurations in remote git repo. It works this time.

spring:
  cloud:
    config:
      allowOverride: true
      overrideNone: true
      overrideSystemProperties: false
Kif answered 9/5, 2017 at 7:21 Comment(3)
What if properties are being fetched from a Config Server? Where are you setting the git repo to fetch values from?Palestine
@PhilipRego Above properties is for config server. You need to explicitly tell config server to allow override by local propertiesAwfully
Great answer except it didn't help.Pate
S
17

From the Overriding the Values of Remote Properties section in Spring Cloud documentation:

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.

So, it must be set in the remote application.yml (e.g. remote git repository). As noted here: "an app can't decide on its own that it can override configuration from the remote source".

Selfpossession answered 18/3, 2019 at 13:9 Comment(6)
Great answer. But one small question. what about bootstrap.yml? If I have a key:value pair in cloud config server and the same key:value pair in my bootstrap.yml, which will take precedence when I start my app? ThanksCaudex
@Caudex as stated here: cloud.spring.io/spring-cloud-static/spring-cloud-commons/… Any properties declared in bootstrap.yml itself have very low precedence (lower than application.yml).Wynny
ok so app.yml takes precedence over bootstrap.yml. what about bootstrap.yml over cloud config server?Caudex
Can you show how to override locally "on the command line". What if I want to set properties locally and quickly while developing without effecting other developers.Palestine
@PhilipRego did u found a way to locally override on cli ?Brutal
@너를속였다 I don't think there's any way to do it. Best option is to upload a new config file like myapp-local.properties and add profile local when running locally.Palestine
A
4

'spring boot app'<-- 'config-server' --> 'config-repo'

Set below properties in application.properties in config-repo

spring.cloud.config.allowOverride=true
spring.cloud.config.overrideNone=true
spring.cloud.config.overrideSystemProperties=false

if remote files are yml then below format

spring:
  cloud:
    config:
      allowOverride: true
      overrideNone: true
      overrideSystemProperties: false
Awfully answered 28/12, 2021 at 11:3 Comment(0)
A
0

Alternative approach is to stop cloud-config for your local testing

spring:
  cloud:
    config:
      enabled: false

Run your IDE with spring.profiles.active = local and add

application-local.yml

file with all needed configs. Yes is not briliant but works for me if you want to test complex properties changes.

Abisha answered 16/4 at 6:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.