Spring cloud config client is not getting/loading configuration files from config server after upgrading to 2.4.0

Viewed 10519

spring-cloud-config-client is not able to read configuration files from the spring-cloud-config-server after upgrading to 2.4.0 with spring-cloud version 2020.0.0-M6

3 Answers

From spring-boot 2.4.0 version, bootstrapping is not enabled by default, need to add the following dependency in your build.gradle

implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap'

or pom.xml

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

Adding to the application file (.properties or .yml) the property spring.config.import , with this it is not necessary to change/add the project's dependencies

Example:

  • To connect with the default location of "http://localhost:8888" or de value defined in the property spring.cloud.config.uri

spring.config.import=optional:configserver:

For more info: https://docs.spring.io/spring-cloud-config/docs/3.0.0/reference/html/#config-data-import

For new spring cloud versions please don't use the legacy dependency spring-cloud-starter-bootstrap instead you need to use application.yml/application.properties instead of bootstrap.yml/bootstrap.properties and then set into that file the following properties:

spring:
  config:
    import: configserver:${your_config_server_url} # example: import: configserver:http://192.168.0.4:8080
  cloud:
    config:
      username: ${your_config_server_auth_user} # This is required only if your config server use authentication
      password: ${your_config_server_auth_password} # This is required only if your config server use authentication
Related