Aggiornare la configurazione durante l'esecuzione
Aggiorni la configurazione senza riavviare i servizi.
Aggiornare la configurazione durante l'esecuzione è una lezione Spring Boot 4 Microservices & REST APIs gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Spring Boot 4 Microservices & REST APIs, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Spring Boot 4 Microservices & REST APIs include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
Config changes without restarts
By default clients read config only at startup. To apply a changed value without restarting, Spring Cloud provides runtime refresh.
The Actuator refresh endpoint
Add Spring Boot Actuator and expose the refresh endpoint. Posting to it makes the client re-fetch config from the server.
management:
endpoints:
web:
exposure:
include: refreshTriggering a refresh
A POST to /actuator/refresh reloads the environment and returns the list of changed property keys.
// POST http://localhost:8080/actuator/refresh
// response: ["app.greeting"] <- keys that changed@RefreshScope
Only beans annotated with @RefreshScope are re-created on refresh, picking up new values. Without it, a bean keeps the value it got at startup.
@RefreshScope
@Component
public class GreetingService {
@Value("${app.greeting}")
private String greeting; // updates after /actuator/refresh
}What gets updated
On refresh, @ConfigurationProperties beans are rebound automatically (no @RefreshScope needed), while @Value-based beans need @RefreshScope to see new values.
How @RefreshScope works
@RefreshScope wraps the bean in a proxy. On refresh the underlying instance is discarded and lazily re-created on next use, so it reads fresh config.
Refresh is per-instance
Calling /actuator/refresh updates only that one instance. In a cluster you must hit every instance - which does not scale well.
Spring Cloud Bus
Spring Cloud Bus links instances over a message broker (RabbitMQ/Kafka). A single /actuator/busrefresh then broadcasts the refresh to all instances at once.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>Automating with webhooks
Connect your Git provider's webhook to the Config Server's monitor endpoint so a push automatically triggers a bus refresh across the fleet - no manual call needed.
What cannot be refreshed live
Some settings only take effect at boot - e.g. server port, datasource URL for an already-built pool, or component scanning. Changing those still requires a restart.
Refresh safely
Treat refresh like a deploy: validate config in Git first, roll out gradually, and watch the returned changed-keys list to confirm only intended values changed.
Quick Check
Test your runtime-refresh knowledge.
Recap
You refreshed config at runtime:
- Expose and POST
/actuator/refresh @RefreshScopere-creates@Valuebeans;@ConfigurationPropertiesrebind automatically- Refresh is per-instance; Spring Cloud Bus broadcasts to all
- Some boot-time settings still need a restart
Domande Frequenti
La lezione «Aggiornare la configurazione durante l'esecuzione» è gratuita?
Sì — il testo completo di «Aggiornare la configurazione durante l'esecuzione» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Spring Boot 4 Microservices & REST APIs, passa a CoddyKit PRO. Il corso Spring Boot 4 Microservices & REST APIs include 4 lezioni in totale.
Cosa imparerò in «Aggiornare la configurazione durante l'esecuzione»?
Aggiorni la configurazione senza riavviare i servizi. Eserciti Spring Boot 4 Microservices & REST APIs con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Spring Boot 4 Microservices & REST APIs?
Non è richiesta alcuna esperienza precedente. Spring Boot 4 Microservices & REST APIs su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Aggiornare la configurazione durante l'esecuzione»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Spring Boot 4 Microservices & REST APIs?
Sì. Ogni lezione Spring Boot 4 Microservices & REST APIs include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Il Config Server
- Configurazione supportata da Git
- Client di configurazione
- Aggiornare la configurazione durante l'esecuzione