16

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.

allenyu5
  • 383
  • 1
  • 2
  • 9
  • Set it in bootstrap.yml in your spring-boot application. – VelNaga May 05 '17 at 10:03
  • @VelNaga 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? – allenyu5 May 08 '17 at 01:41

2 Answers2

19

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

spring:
  cloud:
    config:
      allowOverride: true
      overrideNone: true
      overrideSystemProperties: false
allenyu5
  • 383
  • 1
  • 2
  • 9
  • What if properties are being fetched from a Config Server? Where are you setting the git repo to fetch values from? – Philip Rego Nov 13 '20 at 18:51
11

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".

Community
  • 1
  • 1
lcnicolau
  • 2,520
  • 4
  • 30
  • 48
  • 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? Thanks – theprogrammer Dec 06 '19 at 21:31
  • @theprogrammer as stated here: https://cloud.spring.io/spring-cloud-static/spring-cloud-commons/2.2.2.RELEASE/reference/html/#application-context-hierarchies Any properties declared in bootstrap.yml itself have very low precedence (lower than application.yml). – Grzegorz Poznachowski Apr 21 '20 at 10:12
  • ok so app.yml takes precedence over bootstrap.yml. what about bootstrap.yml over cloud config server? – theprogrammer Apr 21 '20 at 16:46
  • 1
    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. – Philip Rego Nov 13 '20 at 18:55