Spring核心 - 执行顺序

BeanDefinitionRegistryPostProcessor
BeanFactoryPostProcessor
BeanPostProcessor
postProcessBeforeInitialization
postProcessAfterInitialization
PostConstruct
Constructor
Autowired
init-method
afterPropertiesSet

第一步 bean注册
BeanDefinitionRegistryPostProcessor

第二步 bean定义扩展
BeanFactoryPostProcessor

第三步 Constructor 实例化

第四步 Autowired
@Autowired是用于注入对象使用的,那么肯定本对象已经有了才能注入依赖的对象,所以构造器Constructor优先于@Autowired执行

第五步 bean功能扩展BeanPostProcessor
postProcessBeforeInitialization bean初始化之前执行

第六步 PostConstruct
@PostConstruct的描述,必须在所有的依赖都注入,所以@Autowired是优先于@PostConstruct执行的

第七步 afterPropertiesSet 初始化方法
初始化bean的时候执行,可以针对某个具体的bean进行配置。afterPropertiesSet 必须实现 InitializingBean接口。实现 InitializingBean接口必须实现afterPropertiesSet方法

第八步 init-method 初始化方法(xml)

第九步 bean功能扩展BeanPostProcessor
postProcessAfterInitialization bean初始化之后执行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值