版权声明:本文为CSDN博主「lbl2018」的原创文章
一个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
tomcat加载web.xml的过程---StandardContext、ContextConfig源码分析
标签:
原文地点:https://www.cnblogs.com/feng9exe/p/12125509.html
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/32547.html