tomcat加载web.xml
这几天看tomcat的源码,疑问很多,比如之一“ tomcat 怎么加载 web.xml”,下面是跟踪的过程,其中事件监听器有一个观察者模式,比较好。记录下来以供参考
 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>tomcat load web.xml>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    tomcat加载web.xml中用户的servlet到context中去,同时实例化该servlet到/WEB-INF/classes/中
    过程大致如下
    由事件接收器 接收 到CONFIGURE_START_EVENT的消息后,才会触发处理加载web.xml的动作,
            /**
              * The LifecycleEvent type for the "configure_start" event. Used by those
              * components that use a separate component to perform configuration and
              * need to signal when configuration should be performed - usually after
              * {@link #BEFORE_START_EVENT} and before {@link #START_EVENT}.
              */
             public static final String CONFIGURE_START_EVENT = "configure_start";
    那么又是谁来把该消息注册到监听器中的呢?如下,从启动过程中进行查找:
  org.apache.catalina.startup.Bootstrap.start()
   -->org.apache.catalina.startup.Catalina.start()
   ----》load()
   ------》
      getServer().init();
      Server==="org.apache.catalina.core.StandardServer"
      -----》StandardServer.initInternal()
        StandardServer.startInternal()
              ---》
                     void java.org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(String type, Object data)
                             fireLifecycleEvent(CONFIGURE_START_EVENT, null);
                              ---》
                              LifecycleSupport fireLifecycleEvent(CONFIGURE_START_EVENT, null);
                                 由LifecycleSupport 来广播给所有的接收者,
                                  接收者根据需要来判断是否需要处理【此处用到观察者模式 】
                              而public class ContextConfig implements LifecycleListener
                              是所谓的接收者
                              其重写的 lifecycleEvent(LifecycleEvent event)方法中
                               if (event.getType().equals(Lifecycle.CONFIGURE_START_EVENT)) {
                                configureStart();该方法是进行加载的具体方法  
             protected synchronized void configureStart()
                  -----------------》webconfig()
                                                         :::::
                webconfig()中
                            {
                                                     String resource =
                                                             "/WEB-INF/classes/" + binding.getName();
                                                     try {
                                                         URL url = sContext.getResource(resource);
                                                         processAnnotationsUrl(url, webXml,
                                                                 webXml.isMetadataComplete());
                                                     } catch (MalformedURLException e) {
                                                         log.error(sm.getString(
                                                                 "contextConfig.webinfClassesUrl",
                                                                 resource), e);
                                                     }
                            }
    ---------------》
     void java.org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(URL url, WebXml fragment, boolean handlesTypesOnly)
                 ----------》
                  void java.org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(URL url, WebXml fragment, boolean handlesTypesOnly)
                         ------------》
                              void java.org.apache.catalina.startup.ContextConfig.processAnnotationsStream(InputStream is, WebXml fragment, boolean handlesTypesOnly) throws ClassFormatException, IOException
                                     --------------》
                                          void java.org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(String className, AnnotationEntry ae, WebXml fragment)
                                                  ---------》
                                                   fragment.addServlet(servletDef);
                                                   fragment.addServletMapping(urlPattern, servletName);
     ------->webXml.configureContext(context);
                  public void configureContext(Context context) {
                       Wrapper wrapper = context.createWrapper();
                       context.addChild(wrapper);
                       context.addServletMapping(entry.getKey(), entry.getValue());
   >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>tomcat load web.xml>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
tomcat加载web.xml的更多相关文章
- tomcat加载web项目报错:bad major version at offset=6
		分析原因是开发的web项目的java版本高于tomcat使用的java版本,比如我是在java1.6上开发的,但是tomcat使用的java运行环境是1.5,所以会报改错误. 转载博客如下:http: ... 
- web.xml的contextConfigLocation作用及自动加载applicationContext.xml
		web.xml的contextConfigLocation作用及自动加载applicationContext.xml 转自:http://blog.csdn.net/sapphire_aling/ar ... 
- spring boot 加载web容器tomcat流程源码分析
		spring boot 加载web容器tomcat流程源码分析 我本地的springboot版本是2.5.1,后面的分析都是基于这个版本 <parent> <groupId>o ... 
- 在eclipse中启动tomcat加载不了项目的解决方法
		一.在server视图右键选择Add and Remove时,如果想要部署的项目不在左侧的待选列表中,或是弹出警告There are no resources that can be added or ... 
- tomcat下的web.xml和项目中的web.xml
		Tomcat 服务器中存在一个web.xml文件 在项目文件夹中同样存在一个web.xml文件 那这两个文件有什么区别呢? tomcat中的web.xml是通用的,如果不设置,那么就会默认是同tomc ... 
- Tomcat中的Web.xml和servlet.xml的学习
		Web.xml文件使用总结 作用: 存储项目相关的配置信息,保护servlet.解耦一些数据对程序的依赖 使用位置: 每个web项目中 Tomcat服务器中(在服务器目录conf目录中) 区别: We ... 
- 一劳永逸部署项目:通过tomcat加载环境变量
		一劳永逸部署项目:通过tomcat加载环境变量 转载自:https://blog.csdn.net/u010414666/article/details/46499953 一.说明 项目中经常会用到x ... 
- 修改类不用重启Tomcat加载整个项目
		可以修改类不用重启Tomcat加载整个项目(手工启动) 配置reloadable=true(自动重载) 使用Debug模式,前提是仅限于局部修改.(修改类不用重启--热加载) Tomcat轻小,而We ... 
- DB数据源之SpringBoot+MyBatis踏坑过程(二)手工配置数据源与加载Mapper.xml扫描
		DB数据源之SpringBoot+MyBatis踏坑过程(二)手工配置数据源与加载Mapper.xml扫描 liuyuhang原创,未经允许进制转载 吐槽之后应该有所改了,该方式可以作为一种过渡方式 ... 
随机推荐
- POJ 2607 Fire Station
			Fire Station Time Limit: 5000ms Memory Limit: 65536KB This problem will be judged on PKU. Original I ... 
- Qt之图形(组合)
			简述 使用QPainter绘制图形或者图像时,在重叠区域使用组合模式(Composition_mode).在绘图设备上通过组合模式使用QImage时,必须使用Format_ARGB32_Premult ... 
- mac和iphone处理视频
			今天在微信上面发现有视频打不开,也无法下载到相册 而到电脑上可以打开 搜了一下,发现格式不对,mp4有很多格式,有的是苹果支持不了的. 要下载一个转换器,我下载了“超级转霸”,然后把视频转成了ipho ... 
- 具体解释C++引用——带你走进引用的世界
			 一.介绍引用 首先说引用是什么,大家能够记住,引用就是一个别名,比方小王有个绰号叫小狗.他的妈妈喊小狗回家吃饭.那就是在喊小王回家吃饭. 接下来我们用两行代码来声明一个引用(就拿小王和小狗来说吧 ... 
- 覆盖率測试工具gcov的前端工具_LCOV_简单介绍
			1.Gcov是进行代码运行的覆盖率统计的工具.它随着gcc的公布一起公布的,它的使用也非常easy,须要在编译和链接的时候加上-fprofile-arcs -ftest-coverage生成二进制文件 ... 
- WebAPI的自动化监控和预警
			Metrics.net + influxdb + grafana 构建WebAPI的自动化监控和预警 前言 这次主要分享通过Metrics.net + influxdb + grafana 构建Web ... 
- linux下修改完profile文件的环境变量后如何立即生效
			方法1: 让/etc/profile文件修改后立即生效 ,可以使用如下命令: # . /etc/profile 注意: . 和 /etc/profile 有空格 方法2: 让/etc/profile文 ... 
- 什么是SVN(Subversion)? 为什么要用SVN? (2011-09-05 15:09:47) 转载 ▼
			转自:http://blog.sina.com.cn/s/blog_54ccd3500100tkvo.html 什么是SVN(Subversion)? 有一个简单但不十分精确比喻: SVN = 版本控 ... 
- 《剑指offer》反转链表
			一.题目描述 输入一个链表,反转链表后,输出链表的所有元素. 二.输入描述 输入一个链表 三.输出描述 返回逆转后的链表 四.牛客网提供的框架 /* struct ListNode { int val ... 
- Unified BeginFrame scheduling for Chrome
			Unified BeginFrame scheduling for Chrome http://goo.gl/D1Qxrr Status: http://crbug.com/401331 and ht ... 
