I want to develop a module control system so that every spring bean can be managed by my own LifeCycle Controller.
But I can not figure out how can I remove a singleton spring bean out of ApplicationContext.
That may be an interesting problem , can you help me to resolve ?
You can try removing the bean definition. Get the
BeanDefinitionRegistryand callremoveDefinition(..)It depends on the way you create your application, but for example in web application you can get the definition registry by:
(the bean factory implements
BeanDefinitionRegistry).I don’t know if the bean instance will be removed as well. Give it a try.