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要难呢

  • 相关阅读:
    UVA10740 Not the Best (K短路)
    UVA10967 The Great Escape(最短路)
    UVA 10841 Lift Hopping in the Real World(dijkstra)
    U盘启动的PE系统的制作方法
    让远程桌面支持多用户
    学习的书的下载地址
    刚安装完的vs2008写的ajax应用提示sys未定义
    AS3 Libs
    禁用触发器
    Microsoft .NET 类库开发的设计准则
  • 原文地址:https://www.cnblogs.com/zytcomeon/p/15036581.html
Copyright © 2011-2022 走看看