spring @Bean destroyMethod
- Create a Java class and annotate it with @Component or @Service.
- Define a method in the class and annotate it with @Bean.
- Set the destroyMethod attribute of the @Bean annotation to specify the method to be called when the bean is destroyed.
- Spring container will invoke the specified destroy method when the bean is being destroyed, allowing for any necessary cleanup operations to be performed.