InitializingBean接口为bean提供了初始化执行的方法,即afterPropertiesSet方法,凡是继承该接口的类,在初始化bean的时候会执行该方法。

下面简单示例:

这是一个Spring组件Filer:

InitializingBean简单使用

实现了afterPropertiesSet方法:

在这个方法中使用了一个被Autowired注入的Spring Bean:

InitializingBean简单使用

debug启动项目:

可以正常使用被注入的组件!

InitializingBean简单使用

相关文章:

  • 2021-05-24
  • 2022-03-08
  • 2021-11-25
猜你喜欢
  • 2022-12-23
  • 2022-01-29
  • 2021-10-01
  • 2018-04-23
  • 2021-08-15
相关资源
相似解决方案