Skip to content

docs: warn against combining @RefreshScope with @ControllerAdvice beans#1696

Open
won-seoop wants to merge 1 commit into
spring-cloud:mainfrom
won-seoop:doc-1452-refreshscope-controlleradvice-warning
Open

docs: warn against combining @RefreshScope with @ControllerAdvice beans#1696
won-seoop wants to merge 1 commit into
spring-cloud:mainfrom
won-seoop:doc-1452-refreshscope-controlleradvice-warning

Conversation

@won-seoop

Copy link
Copy Markdown

Summary

Closes spring-cloud/spring-cloud-config#1452

When a @ControllerAdvice bean is also annotated with @RefreshScope and 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 @RefreshScope on the @ControllerAdvice and instead extract the refreshable configuration into a separate @RefreshScope or @ConfigurationProperties bean that the advice injects as a normal dependency.

Added a WARNING callout to the @RefreshScope section in application-context-services.adoc documenting this limitation and the recommended approach.

Test plan

  • Docs build with Antora renders the WARNING callout correctly
  • Wording is consistent with maintainer guidance from the issue

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@RefreshScope and component-scanned @ControllerAdvice beans.

2 participants