Search code examples
javaspringspring-bootspring-cloudspring-cloud-config

Spring Cloud - Configuration client caching properties


When I change a value from my properties repository and restart the Spring Cloud Config Server, the changes do not reflect on it's consumers.

my-microservice/application.properties:

spring.application.name=my-service
spring.cloud.config.uri=http://localhost:8888

MyServiceController.java

@RestController
public class MyServiceController {

    @Autowired
    private Configuration configuration;

    @GetMapping("/my-service")
    public MyServiceBean retrieveMyServiceProperties() {
        // show propertie's values
        return new MyServiceBean(configuration.getPropertie1(), configuration.getPropertie2());
    }

}

spring-cloud-config-server/application.properties

server.port=8888
spring.application.name=spring-cloud-config-server

spring.cloud.config.server.git.uri=file://path

Git repo

my-service.properties

my-service.propertie1=1
my-service.propertie2=2

When I send a GET request to localhost:8080/my-service, that's the result I got:

{  
   "propertie1":1,
   "propertie2":2
}

Fine, that's OK! But, if I change the my-service.properties and restart my Spring Cloud Config Server, the changes do not reflect MyServiceController. I do need to restart my-microservice application, for changes to take effect. Is this the normal behavior? I mean, if this is remote, then, it should be configured whether to cache or not.


Solution

  • In order to update the configurations, I sent a POST request to localhost:8080/actuator/refresh.

    By default, /refresh isn't exposed in actuator endpoints.

    I did exposed with the following line in application.properties:

    management.endpoints.web.exposure.include=*
    

    Then, sent a POST request with no body to the endpoint above.