Search code examples
spring-bootspring-cloud-config

Spring Cloud Config refresh configurations


Is it possible to refresh the configurations calling a java method instead to use the REST api:

curl localhost:8080/actuator/refresh -d {} -H "Content-Type: application/json"


Solution

  • You can use the ResartEndpoint class from spring-cloud-context:

    @Autowired
    private RestartEndpoint restartEndpoint;
    
    ...
    
    Thread restartThread = new Thread(() -> restartEndpoint.restart());
    restartThread.setDaemon(false);
    restartThread.start();
    

    This is how @alexbt suggests to do it. But note that the spring cloud documentation also says you can refresh individual beans provided they are RefreshScope.