zoukankan      html  css  js  c++  java
  • tomcat与springmvc 结合 之---第18篇 StandContext容器和SpringMVC的监听器的模型

    writedby张艳涛

    如何使用tomcat的监听器

    public class BootStrap_ex06 {
        public static void main(String[] args) {
            HttpConnector connector = new HttpConnector();
            SimpleWrapper wrapper1 = new SimpleWrapper();
            wrapper1.setName("Primitive");
            wrapper1.setServletClass("PrimitiveServlet");
            SimpleWrapper wrapper2 = new SimpleWrapper();
            wrapper2.setName("Modern");
            wrapper2.setServletClass("ModernServlet");
    
            SimpleContext context = new SimpleContext();
            context.addChild(wrapper1);
            context.addChild(wrapper2);
    
            SimpleContextMapper mapper = new SimpleContextMapper();
            mapper.setProtocol("http");
            SimpleContextLifecycleListener listener = new SimpleContextLifecycleListener();
    
            ((Lifecycle) context).addLifecycleListener(listener);
            context.addMapper(mapper);
            SimpleLoader loader = new SimpleLoader();
    
            context.setLoader(loader);
    
            context.addServletMapping("/Primitive", "Primitive");
            context.addServletMapping("/Modern", "Modern");
            connector.setContainer(context);
    
            try {
                connector.initialize();
                ((Lifecycle) connector).start();
                ((Lifecycle) context).start();
                System.in.read();
                ((Lifecycle) context).stop();
    
            }catch (Exception e){
                e.printStackTrace();
            }
    
        }
    }

    可以看到将一个listener传给context.的lifecyclesupport对象

    那么来看下spring的监听器,起点就是

    FrameworkServlet

    ==>

    createWebApplicationContext

    ==>

    configureAndRefreshWebApplicationContext(wac);
    ==>

    看到了,spring的监听器实现很复杂

    spring的源码读起来比tomcat要难呢

  • 相关阅读:
    安装好php后找不到php.ini
    Nginx 和 PHP 的两种部署方式比较
    高性能Web服务之lnmp架构应用
    >/dev/null 2>&1的含义
    LC_ALL=C的含义
    深入理解PHP Opcode缓存原理
    iostat 监视I/O子系统
    sar 找出系统瓶颈的利器
    Linux常用命令汇总
    linux增加自定义path和manpath
  • 原文地址:https://www.cnblogs.com/zytcomeon/p/15036581.html
Copyright © 2011-2022 走看看