Component 的建立和啟動

來源:互聯網
上載者:User
SpringServerServlet繼承了ServerServlet, 在web.xml聲明了SpringServerServlet。
當Tomcat啟動的時候,會調用ServerServlet的init()方法。
這是Restlet啟動的開始點!


一、init()方法
1、ServerServlet init()方法先擷取 component : 
Component component = getComponent();
2、然後啟動component
component.start();

二、getComponent()方法

1、getComponent()方法首先調用createComponent()建立compoennt
Compoennt component = createComponent();

createComponent的方法在SpringServerServlet 中提供了一個實現。

SpringServerServlet 從Spring環境中以 org.restlet.component 為索引值,擷取 Component 的執行個體。如果沒有,則建立一個新的 Component 執行個體。

這時候,Component執行個體沒有設定 defaultTarget 的值。
2、然後調用 init(component)初始化,完成一些參數的傳遞
init(component  );

三、component.start()方法
此方法在 ServerServlet 類中 init()方法中。
複製代碼
  1. public synchronized void start() throws Exception {
  2.     if (isStopped()) {
  3.             startClients();
  4.             startServers();
  5.             startRouters();
  6.             startServices();
  7.             startRealms();
  8.             startHelper();
  9.             super.start();
  10.      }
  11.     }


其中 startRouters 如下,internalRouter、defaultHost 和 host都是在這裡啟動的:

複製代碼

  1. protected synchronized void startRouters() throws Exception {
  2.         if (this.internalRouter != null) {
  3.         this.internalRouter.start();
  4.         }
  5.         if (this.defaultHost != null) {
  6.         this.defaultHost.start();
  7.         }
  8.         for (VirtualHost host : getHosts()) {
  9.        host.start();
  10.         }
  11.     }


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.