创建一个配置类 BeanConfiguration(标记@Configuration)来创建一堆 Bean 时,如果Bean中有 close()或者 shutdown()  方法,当 AnnotationConfigApplicationContext 的 close 方法被调用时,即当 Spring 容器被销毁时,最终会自动调用依次调用其中的  close()或者 shutdown() 方法
import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;@Configurationpublic class BeanConfiguration {@Beanpublic LightService getTransmission(){return new LightService();}}@Servicepublic class LightService {public void start() {System.out.println("turn on all lights");}public void shutdown() {System.out.println("turn off all lights");}public void check() {System.out.println("check all lights");}}
如何避免
- 不要使用关键字 shutdown 或 close
 - 使用 
@Bean(destroyMethod="") 
