Odświeżanie konfiguracji w czasie działania
Aktualizuj konfigurację bez restartowania usług
Odświeżanie konfiguracji w czasie działania to bezpłatna lekcja Spring Boot 4 Microservices & REST APIs na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Spring Boot 4 Microservices & REST APIs, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Spring Boot 4 Microservices & REST APIs zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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
Ucz się Java dzięki korepetycjom AI — za darmo
Pisz i uruchamiaj kod w przeglądarce, otrzymuj natychmiastową pomoc od korepetytora AI dostępnego 24/7 i kontynuuj naukę w sieci lub w aplikacji.
- Kursy
- 24
- Lekcje
- 93
Często zadawane pytania
Czy lekcja „Odświeżanie konfiguracji w czasie działania” jest bezpłatna?
Tak — pełny tekst „Odświeżanie konfiguracji w czasie działania” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Spring Boot 4 Microservices & REST APIs, przejdź na CoddyKit PRO. Kurs Spring Boot 4 Microservices & REST APIs zawiera 4 lekcji w sumie.
Co nauczysz się w „Odświeżanie konfiguracji w czasie działania”?
Aktualizuj konfigurację bez restartowania usług Ćwiczysz Spring Boot 4 Microservices & REST APIs z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Spring Boot 4 Microservices & REST APIs?
Nie wymagamy żadnego doświadczenia. Spring Boot 4 Microservices & REST APIs w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „Odświeżanie konfiguracji w czasie działania”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Spring Boot 4 Microservices & REST APIs?
Tak. Każda lekcja Spring Boot 4 Microservices & REST APIs zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Serwer konfiguracji
- Konfiguracja oparta na Git
- Klienci konfiguracji
- Odświeżanie konfiguracji w czasie działania