Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeanFactory.getType(String) may not return a Proxy class depending on the order of bean declarations [SPR-9638] #14272

Closed
spring-projects-issues opened this issue Jul 26, 2012 · 5 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jul 26, 2012

Rossen Stoyanchev opened SPR-9638 and commented

When one bean tries to find the type of another, via BeanFactory.getType(String), from an initialization method (e.g. InitializingBean), and when the target bean type is expected to be a JDK dynamic proxy, the actual type returned varies depending on whether the target bean is declared before or after the bean interrogating its type.

This is the mechanism used in Spring MVC to discover and cache @RequestMapping methods to invoke. Hence it's necessary to the presence of JDK proxies.


Affects: 3.1.2

Issue Links:

2 votes, 6 watchers

@spring-projects-issues
Copy link
Collaborator Author

Rossen Stoyanchev commented

I've added a project reproducing the issue:
https://github.com/SpringSource/spring-framework-issues/tree/master/SPR-9638

@spring-projects-issues
Copy link
Collaborator Author

Karsten Sperling commented

I'm having the opposite problem, in that findAnnotationOnBean, which uses getType internally, sometimes does not find annotations. This seems to happen when the bean has already been instantiated, causing getType to return the JDK proxy class rather than the base bean class. In this case findAnnotationOnBean then doesn't find the annotation I'm looking for, even though I got the bean name via getBeanNamesForAnnotation in the first place.

In my case the behaviour is even indeterministic, depending on the (varying) order in which getBeanNamesForAnnotation returns these beans.

@spring-projects-issues
Copy link
Collaborator Author

Marino Debeljuh commented

In version 4.3.10 still having same problem. Event listeners somethime throws exception because of this bug. In EventListenerMethodProcessor getType method is used to find target class but instead of proxy class sometime the real implementation class is returned. Because of that in ApplicationListenerMethodAdapter in method assertTargetBean exception is raised because of wrong method resolution (method from real class is executed on proxy instance)

@spring-projects-issues
Copy link
Collaborator Author

Marino Debeljuh commented

Found quick fix for my problem. getType returns wrong type only for lazy loaded bean (implementation class instead of proxy class). With @Lazy(false) on class getType correctly returns proxy class

@spring-projects-issues spring-projects-issues added type: bug A general bug status: waiting-for-triage An issue we've not yet triaged or decided on in: core Issues in core modules (aop, beans, core, context, expression) and removed type: bug A general bug labels Jan 11, 2019
@rstoyanchev rstoyanchev added status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 11, 2019
@spring-projects-issues
Copy link
Collaborator Author

Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

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) status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process
Projects
None yet
Development

No branches or pull requests

2 participants