predestroy

How to call @PreDestroy for a bean declared with @Bean annotation

谁说胖子不能爱 提交于 2020-01-25 23:04:39
问题 I have a bean declared with annotation @Bean @Bean public Set<DefaultMessageListenerContainer> beans() { Set<DefaultMessageListenerContainer> containerSet = new HashSet<DefaultMessageListenerContainer>(); return containerSet; } I have some operations to be performed when I am destroying the bean. How can I achieve that? 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. EDIT : @Bean