Skip to content

Fix BeanFactory.getBean(String, ParameterizedTypeReference) to respect AOP proxy - #37047

Merged
sbrannen merged 1 commit into
spring-projects:mainfrom
quaff:patch-149
Sep 14, 2026
Merged

sbrannen merged 1 commit into
spring-projects:mainfrom
quaff:patch-149

Conversation

@quaff

@quaff quaff commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Before this commit, the implementation uses ResolvableType::isInstance which doesn't take JDK proxy into account, it fails if proxyTargetClass = false:

Bean named 'userDao' is expected to be of type 'org.springframework.cache.config.ExpressionCachingIntegrationTests$BaseDao<org.springframework.cache.config.ExpressionCachingIntegrationTests$User>' but was actually of type 'org.springframework.cache.config.$Proxy53'
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'userDao' is expected to be of type 'org.springframework.cache.config.ExpressionCachingIntegrationTests$BaseDao<org.springframework.cache.config.ExpressionCachingIntegrationTests$User>' but was actually of type 'org.springframework.cache.config.$Proxy53'
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:212)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1312)
	at org.springframework.cache.config.ExpressionCachingIntegrationTests.expressionIsCacheBasedOnActualMethod(ExpressionCachingIntegrationTests.java:42)

Related Issues

…ect AOP proxy

Before this commit, the implementation uses `ResolvableType::isInstance` which doesn't take JDK proxy into account, it fails if `proxyTargetClass = false`:

```
Bean named 'userDao' is expected to be of type 'org.springframework.cache.config.ExpressionCachingIntegrationTests$BaseDao<org.springframework.cache.config.ExpressionCachingIntegrationTests$User>' but was actually of type 'org.springframework.cache.config.$Proxy53'
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'userDao' is expected to be of type 'org.springframework.cache.config.ExpressionCachingIntegrationTests$BaseDao<org.springframework.cache.config.ExpressionCachingIntegrationTests$User>' but was actually of type 'org.springframework.cache.config.$Proxy53'
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:212)
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1312)
	at org.springframework.cache.config.ExpressionCachingIntegrationTests.expressionIsCacheBasedOnActualMethod(ExpressionCachingIntegrationTests.java:42)
```

See spring-projectsGH-34687

Signed-off-by: Yanming Zhou <zhouyanming@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 Jul 14, 2026
@quaff

This comment was marked as outdated.

@bclozel bclozel added the in: core Issues in core modules (aop, beans, core, context, expression) label Aug 31, 2026
@quaff

quaff commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

I think it's a bug should be fixed ASAP.

@sbrannen sbrannen added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 14, 2026
@sbrannen sbrannen self-assigned this Sep 14, 2026
@sbrannen sbrannen added this to the 7.1.0-M2 milestone Sep 14, 2026
@sbrannen
sbrannen merged commit 74a6c1c into spring-projects:main Sep 14, 2026
5 checks passed
@sbrannen

sbrannen commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

This has been merged into main, and I introduced an additional test in dabd637.

Thanks

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

Labels

in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants