Spring cloud configuration client not downloading configuration from configuration server

I follow this link: http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_client_side_usage

I tested this again and again and don’t see the Spring cloud client downloading the configuration from the cloud server, please help me find out where the error is:

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

  • The configuration server is good: http: // localhost: 8888 / spirent / default

    {"name": "Spirent", "profiles": ["default"], "label": "master", "propertySources": [{"name": "Class path: /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 / cannot be started at all.

    Error creating bean named 'configclientApplication' It seemed that the automatic injection of @Value could not find the value of the production.host environment.

How can I read the configuration on the client after downloading from the configuration server?

Thank you for your help.

+7
spring cloud config
source share
1 answer

As Deinum suggests, I would make sure the client is configured with the parent as spring -cloud-starter-parent and gives it a version. Maven plugins provided by the spring scope will not work when you include in your dependencies and remember that the cloud is a project other than loading. Change it to:

 <parent> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-parent</artifactId> <version>1.0.0.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> 

Secondly, as a new discipline (and probably not your problem here), I would use the new annotation in my application instead of @Configuration and @EnableAutoConfiguration

 @SpringBootApplication 

Third, double check that you have @EnableConfigServer on your configuration server.

Fourth, make sure your bootstrap.properties on your client has the specified spring application name:

 spring.application.name=spirent 

Finally, if you used the spring -cloud-config sample project, your URI has a user password and a default password:

 http://user: ddf4757e-0077-42e4-b2ad-2ae04340b08c@localhost :8888 

Otherwise, try starting with the spring -cloud-config project located here to make sure your configuration server is configured correctly:

 https://github.com/spring-cloud/spring-cloud-config 
+4
source share

All Articles