在下面的类进行注册Bean的一个销毁方式.
    org.springframework.beans.factory.support.AbstractBeanFactory#registerDisposableBeanIfNecessary

    在这个方法内注册DisposableBeanAdapter的bean(就是将DisposableBean放入到 disposableBeans这个LinkedHashMap容器里面)


    什么时候调用destroy方法?
    org.springframework.beans.factory.support.DisposableBeanAdapter#destroy 方法是tomcat调用的,因为只有tomcat知道什么时候销毁容器了,当tomcat容器关闭的时候必定会调用org.springframework.web.context.ContextLoaderListener#contextDestroyed方法(这是Servlet规范,Tomcat必须要调用.)


    Spring内部处理功能
    org.springframework.web.context.ContextLoaderListener#contextDestroyed调用
    org.springframework.web.context.ContextLoader#closeWebApplicationContext方法,再调用
    org.springframework.context.support.AbstractApplicationContext#close方法,再调用
    org.springframework.context.support.AbstractApplicationContext#doClose方法,再调用
    org.springframework.context.support.AbstractApplicationContext#destroyBeans,再调用
    org.springframework.beans.factory.support.DefaultListableBeanFactory#destroySingletons,再调用
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry#destroySingletons,这个方法内部有个disposableBeans容器,这个容器就是装载注册DisposableBeanAdapter的LinkedHashMap容器.然后在内部循环遍历disposableBeans容器,挨个调用
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry#destroySingleton,
    在这个方法内部会删除singletonObjects和singletonFactories和earlySingletonObjects和registeredSingletons容器里面的这个bean的内容(当然如果有的话),然后会删除disposableBeans的内容,获得返回值,这个返回值就是被删除的disposableBeans里面的key对应的value属性,然后再调用
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry#destroyBean,在这个方法获取到Bean实例之后,就可以调用
    org.springframework.beans.factory.support.DisposableBeanAdapter#destroy,就开始调用destroy方法了.