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
相关文章
- spring boot tomcat 打本地包成war,通过Tomcat启动时出现问题: ZipException: error in opening zip file
- tomcat 启动日志乱码,idea中运行Tomcat也出现中文乱码:“淇℃伅”
- Tomcat自启动脚本
- Linux下Tomcat的启动、关闭、杀死进程
- SpringMVC源码总结(五)Tomcat的URIEncoding、useBodyEncodingForURI和CharacterEncodingFilter
- Tomcat 第一篇:源码导入 IDEA 编辑器
- 查看TOMCAT的版本
- Tomcat详解(二)——tomcat安装与配置
- Tomcat详解(一)——tomcat基础知识
- The APR based Apache Tomcat Native library which allows optimal performance in production 问题的解决
- Tomcat卷二---请求流程源码分析
- 关于Tomcat如何处理Open Redirect的问题
- 【项目实战】Tomcat源码分析,热部署原理
- 修改tomcat默认端口
- idea 开启 tomcat 热部署 的 具体流程 和 使用方式
- 使用windos电脑模拟搭建集群(四)web环境 linux+nginx+jdk+tomcat
- Tomcat 加入windows 服务自启动设置
- springboot2使用外部的tomcat服务器创建项目步骤
- Docker Compose部署 nginx代理Tomcat集群
- 探秘Tomcat(一)——Myeclipse中导入Tomcat源码
- Tomcat卷五---Web 应用配置,管理配置和JVM配置
- 【面试】Tomcat面试题
- Tomcat I/O和线程池的并发调优
- Tomcat tomcat-users.xml帮你登录Server Status