On application close, each singleton bean is destroyed by DefaultListableBeanFactory.destroySingletons(). If the bean has a public void no-arg method called shutdown, then it will be invoked. I have some 3rd party beans, all of which implement a certain interface, let's call it DoNotDestroy, that I do not want Spring to destroy.
I can specify a blank string destroy method on each bean, like so:
@Bean(destroyMethod = "")
public MyBean myBean() {
return new MyBean();
}
However, I would prefer to somehow configure Spring to not destroy any beans that implement DoNotDestroy. Is there a good way to do this?