Konfiguration zur Laufzeit aktualisieren
Aktualisieren Sie die Konfiguration, ohne Services neu zu starten.
Konfiguration zur Laufzeit aktualisieren ist eine kostenlose Spring Boot 4 Microservices & REST APIs-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Spring Boot 4 Microservices & REST APIs-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Spring Boot 4 Microservices & REST APIs-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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
Häufig gestellte Fragen
Ist die Lektion „Konfiguration zur Laufzeit aktualisieren“ kostenlos?
Ja — der vollständige Text von „Konfiguration zur Laufzeit aktualisieren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Spring Boot 4 Microservices & REST APIs-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Spring Boot 4 Microservices & REST APIs-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Konfiguration zur Laufzeit aktualisieren“?
Aktualisieren Sie die Konfiguration, ohne Services neu zu starten. Du übst Spring Boot 4 Microservices & REST APIs mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Spring Boot 4 Microservices & REST APIs zu starten?
Keine Vorkenntnisse erforderlich. Spring Boot 4 Microservices & REST APIs auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Konfiguration zur Laufzeit aktualisieren“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Spring Boot 4 Microservices & REST APIs-Lektion Code schreiben und ausführen?
Ja. Jede Spring Boot 4 Microservices & REST APIs-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Der Config Server
- Git-gestützte Konfiguration
- Config Clients
- Konfiguration zur Laufzeit aktualisieren