通过实现InitializingBean和DisposableBean接口来定义初始化和销毁方法
public class Fish implements InitializingBean, DisposableBean { public void destroy() throws Exception { System.out.println("destroy method"); } public void afterPropertiesSet() throws Exception { System.out.println("init method"); } }
init method 容器创建完成 五月 24, 2019 3:05:23 下午 org.springframework.context.annotation.AnnotationConfigApplicationContext doClose 信息: Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@4141d797: startup date [Fri May 24 15:05:23 CST 2019]; root of context hierarchy destroy method