@PreDestroy

An annotation marking a bean method to run while the application context is closing, to release resources the bean owns.

In more detail

It should close only what this bean opened, never a shared resource created elsewhere. Like @PostConstruct it comes from Jakarta Annotations.

Example

@PreDestroy void close() { }

Related terms

Taught in

References