Objects created by FactoryBeans might get processed multiple times by BeanPostProcessors if beans are created lazily [SPR-11937] #16554
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
Andreas Benneke opened SPR-11937 and commented
We wondered why the
ScheduledAnnotationBeanPostProcessor
schedules some of our jobs twice - and tracked this down to this situation.The attached test case is a very simplified version:
BeanImpl1
requiresBeanImpl2
and vice versa).ProxyFactoryBean
in real life, but a simple stripped downSimpleFactoryBean
is sufficient in this case).primary=true
and used for injection.TestPostProcessor
counting the number of invocations ofpostProcessAfterInitialization
per beanName for testing purposes.The test cases reproduce simpler as well as eagerly created versions of this situation:
The
TestPostProcessor
is invoked only once per bean (as expected), ifTestEager*
).TestLazyXml
,TestEagerXml
).TestLazyAutowired
,TestEagerAutowired
).But it is invoked twice (and the tests fail), if the proxies and objects are created lazily (
TestLazyAutowiredFactoryBean
,TestLazyXmlFactoryBean
).While tracing down this situation, we noticed that the
isCurrentlyInCreation
-logic is only applied to theFactoryBeans
itself but not to the objects created by those factories - which might have helped to avoid this duplicate invocation of theBeanPostProcessor
...?Affects: 3.2.9, 4.0.5
Attachments:
Backported to: 3.2.10
The text was updated successfully, but these errors were encountered: