Sobes.tech
Junior — Middle

Have you used the @PreDestroy annotation in your projects?

sobes.tech AI

Answer from AI

The @PreDestroy annotation is used in Java to indicate a method that should be called before a bean is destroyed in the container (for example, in Spring or Java EE).

I used @PreDestroy for resource cleanup, closing connections, or performing other final operations before removing the object from the context.

Example:

@Component
public class MyService {

    @PreDestroy
    public void cleanup() {
        // resource cleanup
        System.out.println("Cleanup before bean destruction");
    }
}

This ensures that the cleanup() method is automatically called when the application shuts down or the bean is destroyed.

Have you used the @PreDestroy annotation in your… - sobes.tech