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 status: bulk-closed

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues 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:

  • #14236 BeanFactory.getType() can return inaccurate (non-proxied) type when using AOP ("is duplicated by")

2 votes, 6 watchers

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 26, 2012

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jul 13, 2016

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

@spring-projects-issues spring-projects-issues commented Nov 5, 2017

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

@spring-projects-issues spring-projects-issues commented Nov 5, 2017

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 status: waiting-for-triage in: core and removed type: bug labels Jan 11, 2019
@rstoyanchev rstoyanchev added status: bulk-closed and removed status: waiting-for-triage labels Jan 11, 2019
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 12, 2019

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 status: bulk-closed
Projects
None yet
Development

No branches or pull requests

2 participants