八、【生命周期】接口InitializingBean和DisposableBean
Bean实现接口InitializingBean和DisposableBean
Bean实体类
/**
* @author zhangjianbing
* @since 2020/9/22
*/
public class BlueYes implements InitializingBean, DisposableBean {
public BlueYes() {
System.out.println("BlueYes...Constructor...");
}
@Override
public void destroy() throws Exception {
System.out.println("BlueYes...destroy...");
}
@Override
public void afterPropertiesSet() throws Exception {
System.out.println("BlueYes...afterPropertiesSet...");
}
}
配置类
@Configuration
public class PersonConfig {
@Bean
public BlueYes blueYes () {
return new BlueYes();
}
}
Bean在初始化和容器关闭的时候会回调接口方法。