title: How to call @PreDestroy for a bean declared with @Bean annotation
body: <p>I have a bean declared with annotation @Bean</p>
  
  <pre><code>@Bean
  public Set&lt;DefaultMessageListenerContainer&gt; beans() {
      Set&lt;DefaultMessageListenerContainer&gt;  containerSet = new HashSet&lt;DefaultMessageListenerContainer&gt;();
  
      return containerSet;
  }
  </code></pre>
  
  <p>I have some operations to be performed when I am destroying the bean. How can I achieve that?</p>
  
  <p>I know I can use @predestroy annotation on a method in a class annotated with @Component but not sure how can I do that when declared @Bean annotation. </p>
  
  <p>EDIT :</p>
  
  <pre><code>@Bean(destroyMethod="stopContainers")
     public Set&lt;DefaultMessageListenerContainer&gt; containers() {
          Set&lt;DefaultMessageListenerContainer&gt;  containerSet = new HashSet&lt;DefaultMessageListenerContainer&gt;();
  
          return containerSet;
      }
  
     public void stopContainers(){
          Set&lt;DefaultMessageListenerContainer&gt;  containerSet = containers();
          ......
          }
  
      }
  </code></pre>
  
  <p>But I am getting an error , Couldn't find a destroy method named 'stopContainers' on bean with name 'containers'
      How to fix this?</p>