This repository was archived by the owner on Apr 14, 2022. It is now read-only.
Fixed BeanPostProcessor detection. #9
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
While playing around with
FunctionalConfigurationI've discovered thatBeanPostProcessorinstances registered in the context viabean()DSL method do not processes the beans as they ought to.The minimal example of such broken configuration is demonstrated below.
What we expect here is that String will be injected into the
AutowireSubjectasautowiredMember. Unfortunately it is not true.I couldn't resist the temptation and investigated this problem a little bit. The issue is that
FunctionalConfiguration#beanmethod registers theFunction0Wrapperinstance which is responsible for creating the actualBeanPostProcessorobject. HoweverAbstractBeanFactory#isFactoryBeanmethod cannot recognize thatFunction0Wrapper#applymethod returnsBeanPostProcessorinstance because the return type of the latter method is parameterized as<T>(i.e. returnsObjectfor the reflection API).I definitely don't feel like Spring internals expert, but the solution that seems reasonable for me is to recognize on the
FunctionalGenericBeanDefinitionlevel if the wrapped function returnsBeanPostProcessor. If so, thenFunctionalGenericBeanDefinitionshould be created with the special version ofFunction0Wrapper#applymethod called (let's say)Function0Wrapper#applyAsBeanPostProcessor. The latter factory method would wrapFunction0<BeanPostProcessor>instances and explicitly defineBeanPostProcessorreturn type. IfFunction0Wrapperfactory method defined onFunctionalGenericBeanDefinitionhas return type ofBeanPostProcessor, thenAbstractBeanFactory#isFactoryBeanworks like a charm. AndAbstractBeanFactory#isFactoryBeanmethod working properly resolves the issue, asAbstractApplicationContext#registerBeanPostProcessorscan recognize that instance return byFunction0Wrapperis aBeanPostProcessor.The pull request contains both fix and test case for it.
Best regards.