Reputation: 177
I have a spring config server running on localhost on port 8888. Here's a snippet from the relevant properties file:
server.port=8085
ideal.connection.threshold.millis=600000
listener.port=3042
number.of.backlog.ports=1000
I am trying to override these properties from command line. I have tried -- and the -D variations, both before and after the <application_name>.jar, but to no avail. The application still picks up the properties from the spring config server.
Things I've tried
java -Dspring.profiles.active=<profile_name> -Dlistener.port=3034 -Dserver.port=9096-Xmx2048m -jar listener-0.0.1-SNAPSHOT.jar
java -Dspring.profiles.active=<profile_name> --listener.port=3034 --server.port=9096-Xmx2048m -jar listener-0.0.1-SNAPSHOT.jar
java -Dspring.profiles.active=<profile_name> -Xmx2048m -jar listener-0.0.1-SNAPSHOT.jar --listener.port=3034 --server.port=9096
java -Dspring.profiles.active=<profile_name> -Xmx2048m -jar listener-0.0.1-SNAPSHOT.jar -Dlistener.port=3034 -Dserver.port=9096
None of the above approaches work, in fact the second approach results in
Unrecognized option: --listener.port=3034
as it should. The other 3 options result in the config being picked up from the spring-config server.
So my question is, is there a way to override the spring config server at all, and if so, what is the right way to override the configurations in the spring config server?
Upvotes: 2
Views: 3347
Reputation: 177
There is a correct and accepted answer to this question, I just thought I'd add some more details.
The official Spring Cloud Config documentation here is quite confusing and misleading. In particular,
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.
It is clear that properties in the config server cannot be overridden via command line, unless you explicitly set the property
spring.cloud.config.override-system-properties
to either true
or false
in the relevant properties file. If you set it to false
, then only the command line, environment variables, and system properties can override the properties. It it is set to true
, then your applications's local config file can override the properties as well.
Thus, if your application name is foo
and active profile is bar
, then your foo-bar.properties
should have the spring.cloud.config.override-system-properties
set to true
or false
.
Note that properties such as application name, profile and the cloud config (things that you'd put in your bootstrap.* file) can, of course, be overridden from the command line.
A big thank you to this github issue, which documents this problem.
Upvotes: 1
Reputation: 3370
When using Spring Cloud Config server, the remote configurations override system configurations (i.e.: command-line arguments are replaced by the remote configs coming from the config server).
To replace this behavior, add the spring.cloud.config.override-system-properties
to false
in your application.properties
.
Upvotes: 5