Bean实现接口InitializingBean和DisposableBean

/**
 * @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在初始化和容器关闭的时候会回调接口方法。

相关文章:

  • 2021-06-21
  • 2021-08-27
  • 2021-06-30
  • 2022-12-23
  • 2021-05-09
  • 2021-04-19
猜你喜欢
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
  • 2021-06-07
  • 2021-07-01
  • 2021-09-07
  • 2020-06-21
相关资源
相似解决方案