Actualizar la configuración en tiempo de ejecución
Actualice la configuración sin reiniciar los servicios
Actualizar la configuración en tiempo de ejecución es una lección gratuita de Spring Boot 4 Microservices & REST APIs en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Spring Boot 4 Microservices & REST APIs, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Spring Boot 4 Microservices & REST APIs incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en 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: 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
Preguntas frecuentes
¿La lección «Actualizar la configuración en tiempo de ejecución» es gratis?
Sí — el texto completo de «Actualizar la configuración en tiempo de ejecución» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Spring Boot 4 Microservices & REST APIs, actualiza a CoddyKit PRO. El curso de Spring Boot 4 Microservices & REST APIs incluye 4 lecciones en total.
¿Qué aprenderé en «Actualizar la configuración en tiempo de ejecución»?
Actualice la configuración sin reiniciar los servicios Practicas Spring Boot 4 Microservices & REST APIs con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Spring Boot 4 Microservices & REST APIs?
No se requiere experiencia previa. Spring Boot 4 Microservices & REST APIs en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.
¿Cuánto tiempo toma la lección «Actualizar la configuración en tiempo de ejecución»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Spring Boot 4 Microservices & REST APIs?
Sí. Cada lección de Spring Boot 4 Microservices & REST APIs incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- El Config Server
- Configuración respaldada por Git
- Clientes de configuración
- Actualizar la configuración en tiempo de ejecución