How can i remove a singleton spring bean from ApplicationContext?

Removing definition does both : removing definition and destroying (removing all container references on that bean) corresponding Singleton :

((BeanDefinitionRegistry) beanFactory).removeBeanDefinition("myBean");

If you just need to remove the singleton then :

((DefaultListableBeanFactory) beanFactory).destroySingleton("myBean");

The latter way may be especially useful if you just registered singleton but haven’t defined any bean definitions, i.e.

((SingletonBeanRegistry) beanFactory).registerSingleton("myBean", myBeanInstance); 

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)