Skip to content

Preserve advisors on early async bean references - #37656

Open
mdnayanmia31 wants to merge 1 commit into
spring-projects:mainfrom
mdnayanmia31:fix/gh-20469
Open

mdnayanmia31 wants to merge 1 commit into
spring-projects:mainfrom
mdnayanmia31:fix/gh-20469

Conversation

@mdnayanmia31

Copy link
Copy Markdown

Closes gh-20469

Overview

When an async bean obtains a self-reference during initialization, caching
advice is attached to its early proxy, but the final bean is wrapped in a
separate async proxy that bypasses that advice. Expose the advisor during
early bean resolution and recognize the underlying singleton target after
initialization so the bean factory reuses the early proxy, including when
another post-processor has already wrapped it.

Tests

Added cacheEvictionWithEarlySelfReference() to
AsyncAnnotationBeanPostProcessorTests. It verifies asynchronous execution,
cache eviction through both the self-reference and the final bean, and that
both references expose the same proxy. The direct eviction assertion failed
before the fix; the complete focused test class passes afterward.

Validated with JDK 25:

  • AsyncAnnotationBeanPostProcessorTests, AopProxyUtilsTests,
    AutoProxyCreatorTests, and DefaultAdvisorAutoProxyCreatorTests.
  • checkstyleMain and checkstyleTest in spring-aop and spring-context.
  • :spring-aop:check :spring-context:check, with unit tests filtered to the
    classes above, including the module runtime-hints checks.

An early self-reference can carry caching advice while the final bean
is wrapped in a separate async proxy, so direct calls bypass the cache.

Expose advisors during early bean resolution and recognize the same
singleton target after initialization to reuse the early proxy.

Closes spring-projectsgh-20469

Signed-off-by: Md Nayan Mia <mdnayanmia31@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 7, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EnableAsync prevents EnableCaching from working in self-injection scenarios [SPR-15915]

2 participants