Nick Allen opened SPR-16249 and commented
If we call destroySingleton it calls destroyBean which remove it's dependency from dependentBeanMap. Then if we call getBean which create that singleton again, dependency won't be added back to dependentBeanMap (Because it should have been added in AutowiredAnnotationBeanPostProcessor.inject but it won't call registerDependentBeans if it is cached).
Solution: Remove metadataCache of bean in injectionMetadataCache when that bean get destroyed.
Affects: 4.3.10
Issue Links: - #21663 BeanDefinition-aware BeanPostProcessors should clear cache in case of bean definition reset
Comment From: spring-projects-issues
Juergen Hoeller commented
Cleaning the local metadata caches in the post-processors is a rather involved affair... It seems more straightforward to simply preserve the dependency maps in DefaultSingletonBeanRegistry
after individual singleton destruction, only clearing them on factory shutdown. We can easily refine this in 5.0.3; it's a tougher call for a backport to 4.3.14 where we are less inclined to accept potential side effects of this.
Comment From: spring-projects-issues
Nick Allen commented
It’s make sense for standard jvm, but dependencies can change if we use dcevm to hot swap classes which add/remove fields.
Comment From: jhoeller
Superseded by #21663.