zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Azureus 3.0.0.8
    KchmViewer 3.0
    GNOME 2.18.0 正式版颁发宣布
    Emacs 22.0.95
    gTwitter:Twitter 的 Linux 客户端
    KDE DVD Authoring Wizard-易用的 DVD 制造器材
    GIMP 2.3.15
    Monit-零碎看监工具
    Cobras-专注于 Qt 的 IDE
    K3b 1.0 正式版公布
  • 原文地址:https://www.cnblogs.com/feng9exe/p/12125509.html
Copyright © 2011-2022 走看看