Spring Bean周期

AnnotationConfigServletWebServerApplicationContext.refresh
ServletWebServerApplicationContext.selfInitialize

 Spring Bean 在整个 SpringBoot 项目中至关重要,它经过的路径如下:

  1. 实例化  【IOC 容器寻找 Bean 的定义信息并将其实例化】
  2. 设置 bean 的 Aware 【Aware 意指能提前感知的,是 spring 的一个重要接口,使用依赖注入,spring 按照 Bean 定义信息配置 Bean 的所有属性】
  3. BeanPostProcessor.postProcessBeforeInitialization(Object bean, String beanName)   【如果 BeanPostProcessor 和 Bean 关联,那么其 postProcessBeforeInitialization () 方法将被调用,Spring 框架会遍历得到容器中所有的 BeanPostProcessor ,挨个执行】
  4. InitializingBean.afterPropertiesSet【初始化 bean, springboot 读取 properties 文件的过程,默认的 application.properties 还有其他方式】
  5. BeanPostProcessor.postProcessAfterInitialization(Object bean, String beanName)  【如果有 BeanPostProcessor 和 Bean 关联,那么其 postProcessAfterInitialization () 方法将被调用】
  6. SmartInitializingSingleton.afterSingletonsInstantiated
  7. SmartLifecycle.start
  8. 运行 Bean
  9. SmartLifecycle.stop(Runnable callback)     
  10. DisposableBean.destroy()     【销毁】

拦截器HandlerInterceptor、ResponseBodyAdvice和@ExceptionHandler执行顺序

执行顺序:

1、HandlerInterceptor.preHandle()

2、 业务方法

3、@ExceptionHandler

4、ResponseBodyAdvice.supports()

5、ResponseBodyAdvice.beforeBodyWrite()

6、HandlerInterceptor.postHandle()

7、HandlerInterceptor.afterCompletion()

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值