spring-cloud-consul icon indicating copy to clipboard operation
spring-cloud-consul copied to clipboard

can't use system properties to override configuration in consul

Open timxi opened this issue 7 years ago • 9 comments

I'm using spring could consul 1.3.2.release version.

Here is my bootstrap.yml:

spring:
  application:
    name: myApp
  cloud:
    config:
      allow-override: true
      override-system-properties: false
      override-none: false
    consul:
      host: localhost
      port: 8500
      config:
        enabled: true

with configuration when I passed -Dmy.prop=system the parameter for my java application, the application still get my.prop from instead of the command line.

I debugged the PropertySourceBootstrapConfiguration source in insertPropertySources method, it seems that spring cloud create new PropertySourceBootstrapProperties with default value in code, it doesn't get the configuration from bootstrap.yml:

	private void insertPropertySources(MutablePropertySources propertySources,
			CompositePropertySource composite) {
		MutablePropertySources incoming = new MutablePropertySources();
		incoming.addFirst(composite);
		PropertySourceBootstrapProperties remoteProperties = new PropertySourceBootstrapProperties();
		new RelaxedDataBinder(remoteProperties, "spring.cloud.config")
				.bind(new PropertySourcesPropertyValues(incoming));
		if (!remoteProperties.isAllowOverride() || (!remoteProperties.isOverrideNone()
				&& remoteProperties.isOverrideSystemProperties())) {
			propertySources.addFirst(composite);
			return;
		}

timxi avatar Feb 13 '18 04:02 timxi

Spring Cloud config properties have no effect on consul config

spencergibb avatar Feb 13 '18 04:02 spencergibb

thanks, @spencergibb, how can I override the configuration value in consul?

for example, I have my.prop=123 in consul, how can I override this via command line?

timxi avatar Feb 13 '18 04:02 timxi

Why do you want to override consul?

spencergibb avatar Feb 13 '18 04:02 spencergibb

sometimes I just want to change some of the application node configurations to do some test not all of the nodes. If I can override the value in consul, it will give me the flexibility to pass the override value via command and restart the individual node.

timxi avatar Feb 13 '18 04:02 timxi

I ran into this issue as well today and you can set the values for spring.cloud.config.allow-override, spring.cloud.config.override-system-properties and spring.cloud.config.override-none but they have to be set in Consul. It feels a bit odd because you cannot configure that along with the rest of the configuration which you put in bootstrap.yml.

jwbennet avatar Mar 08 '18 18:03 jwbennet

@jwbennet setting those values in consul seems wrong, chicken and egg problem.

spencergibb avatar Mar 21 '18 02:03 spencergibb

You can try the following configuration.

default:
  my-prop: default-value 

my:
  prop: ${default.my-prop}

java -jar xxx.jar --default.my-prop=xxx

SystemOutPrint avatar Mar 21 '18 03:03 SystemOutPrint

@SystemOutPrint it's not a bug, I don't need to reproduce it, it's an enhancement request.

spencergibb avatar Mar 21 '18 03:03 spencergibb