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)
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.
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
Attachments:
Issue Links:
The text was updated successfully, but these errors were encountered: