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

  • 相关阅读:
    The Python Standard Library
    Python 中的round函数
    Python文件类型
    Python中import的用法
    Python Symbols 各种符号
    python 一行写多个语句
    免费SSL证书(https网站)申请,便宜SSL https证书申请
    元宇宙游戏Axie龙头axs分析
    OLE DB provider "SQLNCLI10" for linked server "x.x.x.x" returned message "No transaction is active.".
    The operation could not be performed because OLE DB provider "SQLNCLI10" for linked server "xxx.xxx.xxx.xxx" was unable to begin a distributed transaction.
  • 原文地址:https://www.cnblogs.com/kltsee/p/15217083.html
Copyright © 2011-2022 走看看