zoukankan      html  css  js  c++  java
  • ServletWebServerApplicationContext -带有*WebxxxApplication的容器

    ServletWebServerApplicationContext.java

    创建一个容器,在run()方法中被调用。比如调用onRefresh(),把ServletWebServerApplicationContext注册到ServletContext属性中,并调用ServletContextInitializer启动tomcat容器。

    protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {...}
    beanFactory.addBeanPostProcessor(new WebApplicationContextServletContextAwareProcessor(this));
    添加WebApplicationContextServletContextAwareProcessor这个BeanPostProcessor,是为了实现ServletContextAware接口的类能获得ServletContext

    protected void onRefresh() {...}
    createWebServer()
    调用createWebServer(),详解如下

    -createWebServer() {...}
    getSelfInitializer().onStartup(servletContext);
    调用selfInitialize(),把Spring容器(当前实例)注入ServletContext,ServletContextInitializer-》启动容器

    -private void selfInitialize(ServletContext servletContext) throws ServletException {...}

    prepareWebApplicationContext(servletContext);
    // <1> 添加 Spring 容器到 servletContext 属性中。

    registerApplicationScope(servletContext);
    // <2> 注册 ServletContextScope

    WebApplicationContextUtils.registerEnvironmentBeans(getBeanFactory(), servletContext);
    // <3> 注册 web-specific environment beans ("contextParameters", "contextAttributes")

    for (ServletContextInitializer beans : getServletContextInitializerBeans()) {...}
    beans.onStartup(servletContext);
    // <4> 获得所有 ServletContextInitializer ,并逐个进行启动

    -protected void prepareWebApplicationContext(ServletContext servletContext) {...}
    Object rootContext = servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    获取根容器

    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this);
    如果rootContext为空,则把容器设置到servletContext中。

    -finishRefresh(){...}
    super.finishRefresh();

    WebServer webServer = startWebServer();
    启动WebServer

    publishEvent(new ServletWebServerInitializedEvent(webServer, this));
    如果WebServer启动成功,则发布ServletWebServerInitializedEvent事件

    -private WebServer startWebServer() {...}
    webServer.start();
    启动webServer

    TomcatServer

    -public void start() throws WebServerException {...}
    启动tomcat容器
    Connector connector = this.tomcat.getConnector();
    performDeferredLoadOnStartup();

    ======
    带有*WebxxxApplication的容器。会创建创建SpringMVC

  • 相关阅读:
    MySQL如何监测是否命中索引? mysql执行计划解读
    mysql修改用户密码的方法及命令
    php7 安装rabbitmq 扩展 amqp扩展
    HAProxy的高级配置选项-Web服务器状态监测
    HAProxy 配置SSL
    nginx request_body 为空 没有参数 ;关于client_max_body_size client_body_buffer_size配置
    mysql 存储过程 函数的 导入导出
    postman设置客户端证书
    python字符串和列表之间相互转换
    python 发邮件 带附件 给多人发邮件
  • 原文地址:https://www.cnblogs.com/kltsee/p/15217083.html
Copyright © 2011-2022 走看看