• tomcat加载web.xml的过程---StandardContext、ContextConfig源码分析


    一个Context对应一个web应用,而一个web应用应该有一个web.xml
    观察StandardContext的startInternal方法

    startInternal() -> fireLifecycleEvent(Lifecycle.CONFIGURE_START_EVENT, null)
    -> child.start()
    -> mergeParameters()
    -> listenerStart()

    -> setApplicationEventListeners()
    -> setApplicationLifecycleListeners()
    -> filterStart()
    -> loadOnStartup(findChildren())

    (1)fireLifecycleEvent
    StandardContext默认会被添加ContextConfig(Llistener),此时会通知到它,观察ContextConfig的lifecycleEvent方法。

    configureStart()

    -> webConfig()

    -> webXmlParser.parseWebXml()
    -> configureContext(webXml)

    此处会使用digester读取web.xml并设置到StandardContext里。

    (2)mergeParameters
    步骤(1)中会将web.xml中的context-param元素设置到context的parameters里,此处则是把parameters设置到servletContext里。

    (3)启动listener
    步骤(1)中会将web.xml中的listener元素设置到context的applicationListeners里,
    此处则取出listener类名,创建实例,并将listener分为两类
    eventlistener:ServletRequestAttributeListener、ServletRequestListener、HttpSessionIdListener、HttpSessionAttributeListener
    lifecyclelistener:ServletContextListener、HttpSessionListener
    对于ServletContextListener,会调用listener.contextInitialized(event)

    (4)启动filter
    步骤(1)中会将web.xml中的filter元素设置到filter的filterdef里,此处则会实例化filter设置到filterConfigs里。

    (5)启动servlet
    步骤(1)中会将web.xml中的servlet元素封装成wrapper并调用addChild方法设置到Context里,
    此处则会检查是否需要loadonstartup,如果需要则load。


    ————————————————
    版权声明:本文为CSDN博主「lbl2018」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/lblblblblzdx/article/details/80946526

  • 相关阅读:
    全国计算机等级考试二级教程-C语言程序设计_第10章_字符串
    网易云课堂_程序设计入门-C语言_第六章:数组_2鞍点
    arcgis api for silverlight开发系列之二:缓存图层与动态图层及图层总结 .
    VS2010程序打包操作(超详细的)
    地图三要素
    创业建议
    写代码时,必须注意“异常处理”
    WPF——RenderTransform特效
    MVVM特点、源(数据)与目标(如:控件等)的映射
    使用触发器定义 WPF 控件的行为
  • 原文地址:https://www.cnblogs.com/feng9exe/p/12125509.html
Copyright © 2020-2023  润新知