Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
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:
<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 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"
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.
–
–
–
If you are using the 2020.0.0 version of Spring Cloud then you need to add this dependency to your maven dependencies to enable config bootstrap, which is disabled by default in 2020.0.0.
Breaking changes in 2020.0.0
This worked for me.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
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.
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>
–
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
–
–
–
–
–
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
or application.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
In case, anyone is facing this issue on PCF (with marketplace config-server) even after adding spring-cloud-starter-bootstrap
for new spring boot versions, make sure following dependency is added as well -
<dependency>
<groupId>io.pivotal.spring.cloud</groupId>
<artifactId>spring-cloud-services-starter-config-client</artifactId>
</dependency>
It is a problem with spring-boot
versions. Spring-cloud-starter-config
dependency doesn't work well with the older spring-boot version. Try changing your spring-boot
version to some latest version probably above 2.4.0
.
The following gradle
implementation worked for me:
id 'org.springframework.boot' version '2.4.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.