zoukankan      html  css  js  c++  java
  • Spring Bean的生命周期

    《Spring实战》里的图,乍一看很混乱,debug了一下,清楚了些

    原来中间那一大段都在一段逻辑里,可以debug下这段加深印象

    初始化前后调用了许多Processors进行处理的意义是什么?
    实现接口的Processor均可以对bean进行处理,自己定义的processor也可以
        
    Class AbstractAutowireCapableBeanFactory{
      //省略其他方法   
    protected Object initializeBean(final String beanName, final Object bean, RootBeanDefinition mbd) { if (System.getSecurityManager() != null) { AccessController.doPrivileged(new PrivilegedAction<Object>() { public Object run() { AbstractAutowireCapableBeanFactory.this.invokeAwareMethods(beanName, bean); return null; } }, this.getAccessControlContext()); } else {   //处理BeanNameAware、BeanFactoryAwrae、BeanClassLoaderAware this.invokeAwareMethods(beanName, bean); } Object wrappedBean = bean; if (mbd == null || !mbd.isSynthetic()) {   //Processors调用BeforeInitialization方法,ApplicationAware接口在这被处理 wrappedBean = this.applyBeanPostProcessorsBeforeInitialization(bean, beanName); } try {   //afterPropertiesSet调用和init-method方法调用 this.invokeInitMethods(beanName, wrappedBean, mbd); } catch (Throwable var6) { throw new BeanCreationException(mbd != null ? mbd.getResourceDescription() : null, beanName, "Invocation of init method failed", var6); } if (mbd == null || !mbd.isSynthetic()) {   //Processors调用AfterInitialization方法 wrappedBean = this.applyBeanPostProcessorsAfterInitialization(wrappedBean, beanName); } return wrappedBean; } }

    最后的销毁动作调用了DisposableBean的destory()方法,其中调用了destory-method

    class DisposableBeanAdapter implements DisposableBean{
    //省略以上很多方法
      public void destroy() {
      //省略以上一些逻辑
          if (this.destroyMethod != null) {
              this.invokeCustomDestroyMethod(this.destroyMethod);
          } else if (this.destroyMethodName != null) {
              Method methodToCall = this.determineDestroyMethod();
              if (methodToCall != null) {
                  this.invokeCustomDestroyMethod(methodToCall);
              }
          }
    
      }
    }
  • 相关阅读:
    Python 数据类型
    Python 基础
    多表联查和子查询
    python基础中数据类型
    小说体验报告--微信输入法语音转文字--atm转账--签到礼盒的设计点
    PC端和移动端 微信加入群聊--游戏签到 --模拟打车的测试用例设计点
    jmeter连接mysql数据库时报无法创建PoolableConnectionFactory(拒绝用户的root@localhost访问(使用密码:YES))
    jmeter 软件测试
    postman的使用
    Fiddler抓取 模拟机HTTPS包
  • 原文地址:https://www.cnblogs.com/haon/p/11332533.html
Copyright © 2011-2022 走看看