1、方法所属的类继承InitializingBean接口。

2、重写afterPropertiesSet()方法。

afterPropertiesSet方法会在bean被初始化时执行。

当bean的作用域是单例时,afterPropertiesSet方法会随着spring容器的初始化而初始化。

当bean的作用域是原型prototype时,每注入一次bean,都是一个全新的bean,所以afterPropertiesSet方法会在每次注入时执行一次。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案