-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
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:
- Our beans are created lazily.
- We have a set of beans which form a circle (
BeanImpl1requiresBeanImpl2and vice versa). - There are two instances of each bean in the application context, where one is the real implementation.
- The other is a Proxy (created by the
ProxyFactoryBeanin real life, but a simple stripped downSimpleFactoryBeanis sufficient in this case). - The Proxies are marked as
primary=trueand used for injection. - We added a
TestPostProcessorcounting the number of invocations ofpostProcessAfterInitializationper 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), if
- everything is not created lazily (
TestEager*). - there is no circle (not covered in the test cases).
- there are no proxies and everything is defined in XML (
TestLazyXml,TestEagerXml). - there are no proxies and everything is autowired (
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 the FactoryBeans itself but not to the objects created by those factories - which might have helped to avoid this duplicate invocation of the BeanPostProcessor ...?
Affects: 3.2.9, 4.0.5
Attachments:
- spring-factorybean.zip (10.96 kB)
Backported to: 3.2.10