docs: warn against combining @RefreshScope with @ControllerAdvice beans#1696
Open
won-seoop wants to merge 1 commit into
Open
docs: warn against combining @RefreshScope with @ControllerAdvice beans#1696won-seoop wants to merge 1 commit into
won-seoop wants to merge 1 commit into
Conversation
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 spring-cloudgh-1452 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes spring-cloud/spring-cloud-config#1452
When a
@ControllerAdvicebean is also annotated with@RefreshScopeand is component-scanned, Spring MVC detects it in two ways: once through the scope proxy and once directly. This causes methods annotated with@ModelAttribute(and potentially other MVC lifecycle methods) to execute twice per request, which is a subtle and hard-to-debug behavior.The recommended workaround (confirmed by @spencergibb in the issue) is to avoid putting
@RefreshScopeon the@ControllerAdviceand instead extract the refreshable configuration into a separate@RefreshScopeor@ConfigurationPropertiesbean that the advice injects as a normal dependency.Added a
WARNINGcallout to the@RefreshScopesection inapplication-context-services.adocdocumenting this limitation and the recommended approach.Test plan