Spring-cloud-config: Can local config override remote props when running embedded?

Created on 1 Dec 2016  Â·  15Comments  Â·  Source: spring-cloud/spring-cloud-config

Can we make local configuration override remote properties when running embedded server?

I know it's possible when running a Config server and a Config client separately. If I set spring.cloud.config.allowOverride=true on the server and set spring.cloud.config.overrideNone=true on the client, the local configuration overrides the remote.

Some related links regarding this

Is it possible when running embedded server with spring.cloud.config.server.bootstrap=true? I've tried set the properties in the project like below but it didn't work.

spring:
  profiles: default
  cloud:
    config:
      allowOverride: true
      overrideNone: true
      server:
        bootstrap: true
        git:
          uri: file://${user.home}/config

Most helpful comment

@Jeckyli

Thanks @Sangdol for confirming. Now I'm clear that both should reside on config server side, and if I understand correctly, spring.cloud.config.allow-override=true allows system properties from client side to override config server values right?

Right.

so that client will use valueB for this key?

Correct.

All 15 comments

I am sorry I misunderstood. The properties should be in the remote source and it's working fine.

@Sangdol Can you clarify which properties should be in the remote source? My understanding is your original message is correct, that

spring.cloud.config.allowOverride=true in config server
spring.cloud.config.overrideNone=true in config client

and any local property in client can override remote source from server. But seems that this doesn't work for me.

@Jeckyli no, I was wrong and you are making the same mistake as I was.

The both properties (allowOverride, overrideNone) should reside in server config. overrideNone=true makes the server not override clients' properties with the server's properties.

It had been quite confusing for me, and was still not easy to remind correctly; I had to check the note that I've made before.

Thanks @Sangdol for confirming. Now I'm clear that both should reside on config server side, and if I understand correctly, spring.cloud.config.allow-override=true allows system properties from client side to override config server values right?

The problem I'm facing now is I'm trying to have a local prop on config client side to override the same prop from config server, let's say

config server:

key=valueA

In which file (like bootstrap.properties, application.properties or else) should I put on client side

key=valueB

so that client will use valueB for this key?

@Jeckyli

Thanks @Sangdol for confirming. Now I'm clear that both should reside on config server side, and if I understand correctly, spring.cloud.config.allow-override=true allows system properties from client side to override config server values right?

Right.

so that client will use valueB for this key?

Correct.

@Sangdol Thanks, but you've probably misunderstood the last question. I'm wondering where should I put the overriding property on client side. How do you provide the local properties that override default remote ones?

@Jeckyli Sorry, I didn't read your question carefully. Actually it doesn't matter, so it'd be good for you to just put it in application.properties.

Refer to this http://stackoverflow.com/questions/32997352/what-is-the-diference-between-putting-a-property-on-application-yml-or-bootstrap to check the difference between the two files.

This ticket saved my day.

Thank you guys

I am very happy that it helped you. Thanks for the comment.

On Fri, 28 Apr 2017 at 15:41 César Aguilera notifications@github.com
wrote:

This ticket saved my day.

Thank you guys

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/spring-cloud/spring-cloud-config/issues/573#issuecomment-298000689,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAxBlz8h2L8XjUF9KQhNocs1dWNSIzugks5r0eyBgaJpZM4LBPqi
.

I have the same question that: How can I specify a property on client side which it can not be overrided by config server side ?

I don't think that's possible @miqi770. AFAIK, there is no such a level of granularity.

spring.cloud.config.allow-override=true allows _ALL_ application properties defined in the server side be overriden by client-side system properties.

If you want to avoid that a client side property is overriden by a server side one, just use different names in each side (e.g: by using prefixes).

I am trying to follow the comments on this issue but could not make this work.

My Spring Cloud Config Server configuration file looks like:

spring:
  cloud:
    config:
      allow-override: true
      override-none: true
      server:
        default-application-name: application
        default-profile: default
        encrypt:
          enabled: false
        git:
          uri: <here is the url to my repo>

And on my client side bootstrap.properties I set the cloud config server + enable the overrides for config:

spring.cloud.config.uri=http://spring-cloud-config-server:8888
spring.application.name=application
spring.profiles.active=default
spring.cloud.config.override-none=true
spring.cloud.config.fail-fast=true

I had in my client an application.yml file that overrides a value that I set to a default value at application.yml in my git repository, but my application does not get the local overridden value, instead it prints the git repository value.

What am I doing wrong guys?

Solved by comments on: https://github.com/spring-cloud/spring-cloud-config/issues/907

spring:
  cloud:
    config:
      allow-override: true
      override-none: true

Must be added to all desired files at my git repository.

@gcaracuel
hello, what do you mean by all desired files? all those application-{profile}.yml files ?

Exactly + application.yml too if you also need to override values here. I.E.:

At application.yml:
keyA=value1

At application-profile.yml
keyA=value2

And finally at your local application configuration:
keyA=value3

You will need to allow overrides to both 'remote' files if you need keyA to be value3.

Was this page helpful?
0 / 5 - 0 ratings