What happens when there is no destroy method specified for a spring bean?

Viewed 48

Let's say I have 2 beans, Bean A and Bean B. Bean A is a dependency of Bean B. Let's assume I have specified a destroy method for Bean A but not for Bean B. By logic, Bean B should first be destroyed and then Bean A should be destroyed on shutdown. Does Bean B ceases to exist even if no destroy method is specified? If Bean B actually doesn't get destroyed then does Bean A also not get destroyed even though a destroy method has been specified for it?

1 Answers

Think of it that method destroy() always exists for each bean. But by default it is empty. If you need to have some logic executed upon Bean destruction beyond what is done by default than you override this method with your own logic. But just you didn't override such method for some beans does not mean that they are not destroyed.

Related