I am following this link: http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_client_side_usage
I tested this again and again and not seeing Spring cloud client is loading configuration from cloud server, please help to see where is the error:
POM:
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
Application:
@Configuration @EnableAutoConfiguration @RestController public class ConfigclientApplication { @Value("${spring.cloud.config.uri}") String url; @Value("${production.host}") String host; @RequestMapping("/") public String home() { return "Host is => " + this.host ; } public static void main(String[] args) { SpringApplication.run(ConfigclientApplication.class, args); } }
bootstrap.properties: spring.cloud.config.uri=http://localhost:8888
{ "name": "spirent", "profiles": [ "default" ], "label": "master", "propertySources": [ { "name": "classpath:/spirent.yml", "source": { "production.host": "server1", "production.port": 9999, "production.value1": 12345, "test.host": "server2.com", "test.port": 4444, "test.value": "hello123" } } ] }
now http://localhost:8080/ can not be started at all.
Error creating bean with name 'configclientApplication' It seemed the auto inject of @Value can not find the production.host environment value.
How can I read the configuration in client once loaded from config server?
Thanks for your help.
7.1 Config First Bootstrap The default behavior for any application that has the Spring Cloud Config Client on the classpath is as follows: When a config client starts, it binds to the Config Server (through the spring. cloud.
If you are using 2020.0.0 version of spring cloud than you need to this dependency in your maven dependencies to enable bootstrap, which is desabled by default in 2020.0.0.
Breaking changes in 2020.0.0
It work for me.
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bootstrap</artifactId> </dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With