From b20f00b93f4585d3f152ae01780598d5af7fb0a5 Mon Sep 17 00:00:00 2001 From: halo Date: Wed, 10 Jun 2026 08:51:48 +0900 Subject: [PATCH] docs: warn against combining @RefreshScope with @ControllerAdvice beans When a @ControllerAdvice bean is annotated with @RefreshScope and is component-scanned, Spring MVC detects it both through the scope proxy and directly. This causes @ModelAttribute methods (and other MVC lifecycle methods) to execute twice per request. Added a WARNING to the @RefreshScope section documenting this limitation and recommending extracting refreshable configuration into a separate @RefreshScope (or @ConfigurationProperties) bean instead. Closes gh-1452 Co-Authored-By: Claude Sonnet 4.6 --- .../spring-cloud-commons/application-context-services.adoc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/modules/ROOT/pages/spring-cloud-commons/application-context-services.adoc b/docs/modules/ROOT/pages/spring-cloud-commons/application-context-services.adoc index 82644aca0..451589247 100644 --- a/docs/modules/ROOT/pages/spring-cloud-commons/application-context-services.adoc +++ b/docs/modules/ROOT/pages/spring-cloud-commons/application-context-services.adoc @@ -214,6 +214,10 @@ Specifically, anything that depends on those beans cannot rely on them being upd In that case, it is rebuilt on a refresh and its dependencies are re-injected. At that point, they are re-initialized from the refreshed `@Configuration`). +WARNING: Do not combine `@RefreshScope` with Spring MVC lifecycle beans such as `@ControllerAdvice`. +Spring MVC detects `@ControllerAdvice` beans both through the scope proxy and directly, which causes `@ModelAttribute` methods to execute twice per request. +Instead, extract refreshable configuration into a separate `@RefreshScope` bean (or a `@ConfigurationProperties` bean) that your `@ControllerAdvice` injects as a regular dependency. + NOTE: Removing a configuration value and then performing a refresh will not update the presence of the configuration value. The configuration property must be present in order to update the value after a refresh. If you are relying on the presence of a value in your application you might want to switch your logic to rely on its absence instead. Another option would be to rely