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

InstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation called with wrong beanClass for bean declared on JavaConfig [SPR-12142] #16756

spring-projects-issues opened this issue Sep 1, 2014 · 1 comment
in: core type: bug


Copy link

@spring-projects-issues spring-projects-issues commented Sep 1, 2014

Arrault Fabien opened SPR-12142 and commented

When a bean is created with JavaConfig with a @Bean method WITH the static modifier (there is another issue without the static modifier : #16754), the method postProcessBeforeInstantiation of InstantiationAwareBeanPostProcessor beans is called with the wrong beanClass parameter :
This parameter is populated with the beanClass of the @Configuration class containing the @Bean method instead of the target beanClass of the bean being about to be created.

See testcase attached

This method is correctly called when the bean is declared in an XML File.

This sometimes causes troubles in edge cases when using of LazyInitTargetSourceCreator on JavaConfig (see #15140)

Affects: 4.0.6


Issue Links:

  • #15140 LazyInitTargetSourceCreator does not work in Java-based configuration ("is depended on by")
  • #16754 InstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation not called for bean declared on JavaConfig
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 2, 2014

Juergen Hoeller commented

Indeed, we need to call postProcessBeforeInstantiation with a properly resolved bean type, like we do in other places. Up until this point, we simply always took the bean definition's raw bean class... which in the case of a static factory method was at least available (i.e. the class that the factory method is defined on), while for a non-static factory method, it wasn't even there (since they are delegated to a target factory bean by name) - which is why our algorithm didn't even call postProcessBeforeInstantiation (it required the bean class to be non-null). Both cases have been fixed for 4.1 now.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: core type: bug
None yet

No branches or pull requests

2 participants