Reputation: 81
I am using Spring Boot in combination with Spring Cloud Config Client to manage the configuration for my microservice. Additionally, I have a Spring Cloud Config Server to provide the configuration.
My microservice is designed to fetch configuration from the Spring Cloud Config Server, but if it's unavailable, it should fall back to using program parameters as default values. However, the issue I'm facing is that the program parameters are overriding the configuration fetched from the Spring Cloud Config Server.
Example:
Start of microservice: java -jar microservice.jar --setting.parameter=1
application.yml of microservice
spring:
config:
import: optional:configserver:http://localhost:8880
remote application.yml in github repo for microservice:
setting:
parameter: 2
result: The microservice application starts with setting.parameter=1. If i am starting the application without program parameters the result is setting.parameter=2
Upvotes: 2
Views: 558
Reputation: 81
I found the solution by myself. If you are using spring cloud on client side you should not put the spring.config.import
in the application.yml
. Instead you should put it into the bootstrap.yml
.
Technically, bootstrap.yml
is loaded by a parent Spring ApplicationContext. That parent ApplicationContext is loaded before the one that uses application.yml
.
Conclusion: If you put the spring.config.import
into application.yml
the program parameters
override the spring cloud config
. If you put it into the bootstrap.yml
the spring cloud config
overrides the program parameters
Credits to:
Upvotes: 3
Reputation: 1
i think spring boot precedence for cmd parameters is greater than the property file. So this is an expected behaviour. Since the application.properties values are treated as env variables, the values passed as input to jar has higher priority ie property in:
java -jar microservice.jar --setting.parameter=1
priority is greater than the one present in property file or read from config server.
Upvotes: 0