spring @Bean destroyMethod

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