0Pricing
Spring Boot 4 Microservices & REST APIs · Pelajaran

Menyegarkan Konfigurasi saat Runtime

Perbarui konfigurasi tanpa memulai ulang layanan.

Menyegarkan Konfigurasi saat Runtime adalah pelajaran Spring Boot 4 Microservices & REST APIs gratis di CoddyKit. Ini adalah pelajaran 4 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Spring Boot 4 Microservices & REST APIs, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Spring Boot 4 Microservices & REST APIs mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

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: refresh

Triggering 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
  • @RefreshScope re-creates @Value beans; @ConfigurationProperties rebind automatically
  • Refresh is per-instance; Spring Cloud Bus broadcasts to all
  • Some boot-time settings still need a restart

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Menyegarkan Konfigurasi saat Runtime” gratis?

Ya — teks lengkap “Menyegarkan Konfigurasi saat Runtime” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Spring Boot 4 Microservices & REST APIs, upgrade ke CoddyKit PRO. Kursus Spring Boot 4 Microservices & REST APIs mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Menyegarkan Konfigurasi saat Runtime”?

Perbarui konfigurasi tanpa memulai ulang layanan. Kamu berlatih Spring Boot 4 Microservices & REST APIs dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai Spring Boot 4 Microservices & REST APIs?

Tidak diperlukan pengalaman sebelumnya. Spring Boot 4 Microservices & REST APIs di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 4 dari 4.

Berapa lama pelajaran “Menyegarkan Konfigurasi saat Runtime” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran Spring Boot 4 Microservices & REST APIs ini?

Ya. Setiap pelajaran Spring Boot 4 Microservices & REST APIs menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Server Konfigurasi
  2. Konfigurasi Berbasis Git
  3. Klien Konfigurasi
  4. Menyegarkan Konfigurasi saat Runtime
← Kembali ke Spring Boot 4 Microservices & REST APIs