Refreshing Configuration

Refresh One Instance

Config is read at startup. To pick up a change without restarting, call the actuator refresh endpoint (it must be exposed). Spring re-fetches config, rebinds @ConfigurationProperties beans and re-creates beans marked @RefreshScope:

@RestController
@RefreshScope                          // re-created after /actuator/refresh
class SaleBannerController {

    @Value("${shopease.sale.banner:Welcome to ShopEase}")
    private String banner;

    @GetMapping("/api/orders/banner")
    String banner() {
        return banner;
    }
}

Example

Change shopease.sale.banner in the repo, push, then:

git commit -am "Diwali sale banner" && git push
curl -X POST localhost:8082/actuator/refresh
curl localhost:8082/api/orders/banner

Example output

["shopease.sale.banner"]

Diwali Sale: up to 70% off!

Refresh All Instances with Spring Cloud Bus

With 6 instances, calling each one is painful. Spring Cloud Bus links instances through Kafka or RabbitMQ. One call to /actuator/busrefresh broadcasts a refresh event to every instance:

git push -> (webhook) -> Config Server  POST /actuator/busrefresh
                                |
                         [ Kafka topic: springCloudBus ]
                 /              |               \
          order #1          order #2          product #1   ... all refresh
<!-- every service + the config server -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bus-kafka</artifactId>   <!-- or -bus-amqp -->
</dependency>

Tip: Add spring-cloud-config-monitor to the Config Server and point a GitHub webhook to /monitor: a push then triggers the bus refresh automatically.

What Can and Cannot Be Refreshed

Refreshes liveNeeds a restart
Feature flags, limits, messages, timeouts read through @ConfigurationPropertiesserver.port
@Value fields in @RefreshScope beansDatasource URL (connection pool already created)*
Logging levels (logging.level.*)Beans created once at startup without @RefreshScope

* A @RefreshScope DataSource is possible but rarely worth it. Restarting with a rolling deploy is simpler and safer.