0Pricing
Spring Boot 4 Microservices & REST APIs · Урок

Обновление конфигурации во время работы

Обновляйте конфигурацию без перезапуска сервисов

«Обновление конфигурации во время работы» — бесплатный урок Spring Boot 4 Microservices & REST APIs на CoddyKit. Это урок 4 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Spring Boot 4 Microservices & REST APIs, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Spring Boot 4 Microservices & REST APIs содержит 4 уроков всего.

Части этого урока еще не переведены и отображаются на английском.

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

Часто задаваемые вопросы

Урок «Обновление конфигурации во время работы» бесплатный?

Да — полный текст урока «Обновление конфигурации во время работы» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Spring Boot 4 Microservices & REST APIs, подпишись на CoddyKit PRO. Курс Spring Boot 4 Microservices & REST APIs содержит 4 уроков всего.

Чему я научусь в уроке «Обновление конфигурации во время работы»?

Обновляйте конфигурацию без перезапуска сервисов Ты практикуешь Spring Boot 4 Microservices & REST APIs с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать Spring Boot 4 Microservices & REST APIs?

Предыдущий опыт не требуется. Spring Boot 4 Microservices & REST APIs на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 4 из 4.

Сколько времени занимает урок «Обновление конфигурации во время работы»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке Spring Boot 4 Microservices & REST APIs?

Да. Каждый урок Spring Boot 4 Microservices & REST APIs включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Сервер конфигурации
  2. Конфигурация на основе Git
  3. Клиенты конфигурации
  4. Обновление конфигурации во время работы
← Назад к Spring Boot 4 Microservices & REST APIs