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

  • 相关阅读:
    利用Form组件和ajax实现的注册
    基于ajax实现的登录
    【字符串】【kmp模板】
    【字符串入门专题1】 I
    【字符串入门专题1】A
    【最短路入门专题1】H
    【最短路入门专题1】D
    【最短路入门专题1】E
    【最短路径入门专题1】K
    【多校连萌2】D题 ykc想吃好吃的【补题】【最大子段和变形题】
  • 原文地址:https://www.cnblogs.com/zytcomeon/p/15036581.html
Copyright © 2011-2022 走看看