Description

Hello team, the following is what I am doing

I have a Spring Config Server running. It is using git to check for configuration changes

spring.cloud.config.server.git.uri=${HOME}/configRepo

^ on the above location, I have a file appllication-production.yml which I update and want to have the changes in this reflected on my cloud client without restart

I also have a Spring Client which connects to the Spring Config Server

The following are the yml files used for configuration in client's resources folder.

application.yml

spring:
  cloud:
    config:
      enabled: true
  profiles:
    include: production

management:
  endpoints:
    web:
      exposure:
        include: ["*"]

application-production.yml

product:
    name: Cloud_Demo
    data:
        first_key: "some_value"
        second_key: "some_value"

I am reading the above, using

@Getter
@Setter
@Validated
@ConfigurationProperties(prefix = "product")
@Component
public class ProductConfiguration {

  private String name;
  private LinkedHashMap<String, String> data;

}

And then I have this file, which invokes refresh endpoint of actuator to reload config. And it works perfectly fine.

@Configuration
@EnableScheduling
public class RefreshConfig {

  private RefreshEndpoint refreshEndpoint;

  public RefreshConfig(RefreshEndpoint refreshEndpoint) {
    this.refreshEndpoint = refreshEndpoint;
  }

  @Scheduled(fixedDelay = 20000, initialDelay = 20000)
  public void refreshContextPeriodically() {

    System.out.println("Refreshing Context");
    refreshEndpoint.refresh();
  }
}

ISSUE

So I understand that, Config Server is looking at the above git repo and when I change the file - application-production.yml it knows about this change.

Now, when my RefreshConfig calls refresh endpoint on my client, it gets these changes without restart.

However, when the client restarts these changes are lost. The issue I am facing is - when the Client restarts, it falls back to the file application-production.yml in the client resources folder.

This is bad since, say I have my client running in production, and there was a need to change some configuration. I changed that and client gets new config. However, say for some reason if the client restarted, then this newly changed config will be lost.

How do I make sure that once I change application-production.yml in my git repo, even if the client restarts, it gets the changes from application-production.yml in my git repo and not from application-production.yml in the resources folder.

Comment From: ShraddhaChitalia

Closing this since I just noticed that - after client restart, when my refresh endpoint gets invoked, it does get the latest changes which were made to the file on github. Looks like I should keep the initialDelay small so that each time it restarts, it picks up the latest changes from git