spring cloud config client not loading configuration from config server
Solution 1:
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>
Solution 2:
For those getting here after using the default Maven Spring Cloud dependency version related to Spring Boot to 2.4.0 or 2.4.1 (e.g., 2020.0.0-M5 for Spring Boot 2.4.0), besides following RubesMN's good advice, be aware that bootstrapping is not enabled by default in such Spring Cloud dependency. According to the Spring Cloud 2020.0 Release Notes:
Bootstrap, provided by spring-cloud-commons, is no longer enabled by default. If your project requires it, it can be re-enabled by properties or by a new starter.
- To re-enable by properties set spring.cloud.bootstrap.enabled=true or spring.config.use-legacy-processing=true. These need to be set as an environment variable, java system property or a command line argument.
- The other option is to include the new spring-cloud-starter-bootstrap (in your POM file).
I used the second option and worked just fine.
Solution 3:
If you are using 2020.0.0 version of spring cloud then you need to add this dependency in your maven dependencies to enable bootstrap, which is disabled by default:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
Solution 4:
As Deinum implies, I'd ensure you have the client configured with the parent as spring-cloud-starter-parent and give it a version. Maven plugins provided by spring cloud wont work when you include in your dependencies and remember cloud is a different project than boot. 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>
Second, as a new discipline (and likely not your problem here), I'd use the new annotation on your Application instead of @Configuration and @EnableAutoConfiguration
@SpringBootApplication
Third, double check you have @EnableConfigServer on your config server
Fourth, be sure your bootstrap.properties on your client has your spring application name specified:
spring.application.name=spirent
Finally, if you used the spring-cloud-config example project, there is a default user and security password that you have to set in your URI:
http://user:ddf4757e-0077-42e4-b2ad-2ae04340b08c@localhost:8888
Otherwise, try starting from the spring-cloud-config project located here to ensure your config server is setup correctly:
https://github.com/spring-cloud/spring-cloud-config
Solution 5:
I am adding my findings. For me, after spending healthy 2 hours I found that,
-
Config Server should have: [
spring-cloud-config-server
]<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.3</version> <relativePath/> </parent> <properties> <java.version>1.8</java.version> <spring-cloud.version>2020.0.3</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> </dependencies>
-
Client Services should have: [
spring-cloud-starter-config
]<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.3</version> <relativePath/> </parent> <properties> <java.version>1.8</java.version> <spring-cloud.version>2020.0.3</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> </dependencies>
-
Client Services should declare: in
application.properties
orapplication.yml
#This does not work #spring.cloud.config.uri=http://localhost:8880/config-server spring.application.name=name-by-which-properties/yml-file-is-created spring.config.import=optional:configserver:http://host:port/application-context management.endpoints.web.exposure.include=*
What did not work for me:
- Adding
spring-cloud-starter-bootstrap
- Adding
spring-cloud-starter-parent
Hope this will help others like me with Spring Boot (2.5.3)
and Spring Cloud 2020.0.3