can't use system properties to override configuration in consul
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;
}
Spring Cloud config properties have no effect on consul config
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?
Why do you want to override consul?
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.
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 setting those values in consul seems wrong, chicken and egg problem.
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 it's not a bug, I don't need to reproduce it, it's an enhancement request.