From the course: Spring: Framework in Depth

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

The destruction phase

The destruction phase

From the course: Spring: Framework in Depth

Start my 1-month free trial

The destruction phase

- [Instructor] When your application begins to shut down, hopefully on purpose, you enter the destruction phase of the life cycle. Now, the destruction phase is really critical because this is when Spring itself goes out of context. And it begins when close is called on the ApplicationContext. So there is a method called close that you can call. Now, if you just shut your application down, close will be called as well in a roundabout way. Any @PreDestroy method is called when close is called on the ApplicationContext. And again, this is that life cycle method that gave you the last chance to do work before Spring itself goes out of scope. It's important to note that beans are not destroyed. This is Java. You can't destroy the beans anywhere. Only the garbage collector can do that. So beans are not destroyed. They're not de-referenced until close occurs. Then they are de-referenced and marked as available for garbage…

Contents