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);
              }
          }
    
      }
    }
  • 相关阅读:
    织梦DedeCms调用全站相关文章方法
    利用dedecms autoindex让文章列表加上序列号
    织梦技巧之---织梦dedecms后台验证码错误的解决方法
    在织梦后台全站更新是出现“DedeTag Engine Create File False”错误的解决办法
    DEDECMS后台空白,dede网站栏目管理空白解决方法
    dedeCms搬家说明-官方教程绝对有够详细
    教你织梦DEDE自动更新首页的办法
    DSP using MATLAB 示例Example2.12
    DSP using MATLAB 示例Example2.11
    DSP using MATlAB 示例Example2.10
  • 原文地址:https://www.cnblogs.com/haon/p/11332533.html
Copyright © 2011-2022 走看看