Refresh Property Config at Runtime in Spring Cloud Config

author-image   By Dhiraj,   26 February, 2018 46K

In this tutorial series of spring cloud config, we will be discussing about refreshing property configuration at run-time.We will be doing so using spring boot actuator /refresh endpoint. Also, we will take a look into refreshing @Value properties using @RefreshScope annotation.

In my last tutorial of spring cloud config, we set up a cloud config service with discovery server and discovery client and successfully created an example to read application configuration properties in a distributed environment with GIT backened store.Here, we will continue from there to demo the functionality of refreshing property configuration in spring cloud config at run-time.

In this article we will be only focussing on refreshing config properties. So, we will not be using discovery server related configuration. We will have a config server to load properties from GIT store and config client with actuator project.

Different Ways to Refresh Properties

A simple way to refresh configuration property is to use /refresh endpoint provided by spring boot actuator.But this is a manual process and need to be triggered for all the instances.Another way is with /bus/refresh with spring-cloud-bus and in this case all the instances subscribe to an event and whenever this event is triggered, all the config properties will be automatically refreshed via spring cloud bus broadcasting.And the third way to refresh these properties is by hooking up with VCS. In this article we will be dealing with spring boot actuator refresh endpoint.

Spring Cloud Config Server Implementation

We already have the setup ready for this implementation in my previous article. Here let us briefly discuss about it. We have following defined in config server and spring boot main application.It exposes REST endpoint as http://localhost:8888 for the client to get the configuration properties.
package com.devglan.springcloudconfigexample;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class SpringCloudConfigExampleApplication {

	public static void main(String[] args) {, args);

We have our external configuration properties defined at, we have properties defined for active profile local and global properties.

Spring Cloud Config Client Implementation

For client we have following defined.This is the same file we defined in our previous app here

Refreshing Configuration Properties with /refresh Endpoint

/refresh endpoint only refreshes those properties annotated with @ConfigurationProperties means it does not refresh those properties which are initialized during app initialization. For example we have following configuration class defined that reads property having prefix random

package com.devglan.springcloudconfigclient;

import org.springframework.stereotype.Component;

public class PropertyConfiguration {

    private String property;

    public String getProperty() {
        return property;

    public void setProperty(String property) { = property;

We have following controller class that uses property prefixed with random and also reads property annotated with @Value

public class DemoController {

    private String testProperty;

    private String localTestProperty;

    private PropertyConfiguration propertyConfiguration;

    public String test() {
        StringBuilder builder = new StringBuilder();
        builder.append("global property - ").append(testProperty).append(" || ")
                .append("local property - ").append(localTestProperty).append(" || ")
                .append("property configuration value - ").append(propertyConfiguration.getProperty());
        return builder.toString();

For endpoint http://localhost:8080/spring-cloud-config-client/ following will be the output.


Now let us change the configuration proprties defined in the as below. local property changed property changed

Now we will be calling the http://localhost:8080/spring-cloud-config-client/refresh POST method of actuator to refresh the property. Following will be the response with the updated properties.


Now if we hit http://localhost:8080/spring-cloud-config-client/ we can see that property coming from class annotated with @ConfigurationProperties has been updated but the property annotated with @Value has not been updated because this is initializes during application startup


To update property annotated with @Value, we need to annotate the class with @RefreshScope. Hence, here we will be annotating controller class with @RefreshScope and restart the client app.After restart again we will make change in the properties file and push the changes to git. This time we have appended the properties value with string twice and again we call the refresh endpoint again. Now, if we hit the url http://localhost:8080/spring-cloud-config-client/ we can find that both the configuration properties annotated with @Value and @ConfigurationProperties has been updated. config-property-refresh

If You Appreciate This, You Can Consider:

  • Like us at: Facebook or follow us at Twitter
  • Share this article on social media or with your teammates.
  • We are thankful for your never ending support.

About The Author


I am an energetic professional who enjoys the challenges involved in working with people and resolving real-time problems. Technical expertise in building highly scalable, distributed and self-healing cloud applications. Technical Skills: Java/J2EE, Spring Framework, Hibernate, Angular, Reactive Programming, Microservices, Rest APIs, Kafka, ELK, etc.

Further Reading on Spring Cloud

1 Spring Boot Redis Cache

2 Spring Cloud Gateway Example

3 Spring Cloud Config

4 Spring Cloud Netflix Eureka

5 Introduction To Microservices

6 Encrypt Decrypt Cloud Config Properties

7 Spring Netflix Zuul