0Pricing
Spring Boot 4 Microservices & REST APIs · Aula

Atualizando a configuração em tempo de execução

Atualize a configuração sem reiniciar os serviços.

Atualizando a configuração em tempo de execução é uma aula grátis de Spring Boot 4 Microservices & REST APIs no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Spring Boot 4 Microservices & REST APIs, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Spring Boot 4 Microservices & REST APIs inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

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

Perguntas Frequentes

A aula “Atualizando a configuração em tempo de execução” é grátis?

Sim — o texto completo de “Atualizando a configuração em tempo de execução” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Spring Boot 4 Microservices & REST APIs, atualize para CoddyKit PRO. O curso de Spring Boot 4 Microservices & REST APIs inclui 4 aulas no total.

O que vou aprender em “Atualizando a configuração em tempo de execução”?

Atualize a configuração sem reiniciar os serviços. Você pratica Spring Boot 4 Microservices & REST APIs com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Spring Boot 4 Microservices & REST APIs?

Nenhuma experiência prévia é necessária. Spring Boot 4 Microservices & REST APIs no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Atualizando a configuração em tempo de execução”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Spring Boot 4 Microservices & REST APIs?

Sim. Cada aula de Spring Boot 4 Microservices & REST APIs inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. O servidor de configuração
  2. Configuração respaldada pelo Git
  3. Clientes de configuração
  4. Atualizando a configuração em tempo de execução
← Voltar para Spring Boot 4 Microservices & REST APIs