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

  • 相关阅读:
    FZU 2113 BCD Code 数位dp
    Gym 100917L Liesbeth and the String 规律&&胡搞
    Gym 100917C Constant Ratio 数论+暴力
    CF149D Coloring Brackets
    P4342 [IOI1998]Polygon
    P4316 绿豆蛙的归宿
    P1439 【模板】最长公共子序列
    Noip 2013 真题练习
    洛谷比赛 「EZEC」 Round 4
    P5024 保卫王国
  • 原文地址:https://www.cnblogs.com/zytcomeon/p/15036581.html
Copyright © 2011-2022 走看看