Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring cloud config client not loading configuration from config server

Tags:

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

  1. The config server is good: http://localhost:8888/spirent/default
{   "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"       }     }   ] } 
  1. 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.

like image 636
user3006967 Avatar asked May 03 '15 17:05

user3006967


People also ask

When a config client starts it binds to the config server through the?

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.


1 Answers

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> 
like image 80
Vijay Patidar Avatar answered Oct 02 '22 00:10

Vijay Patidar