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()方法中。
複製代碼
- public synchronized void start() throws Exception {
- if (isStopped()) {
- startClients();
- startServers();
- startRouters();
- startServices();
- startRealms();
- startHelper();
- super.start();
- }
- }
其中 startRouters 如下,internalRouter、defaultHost 和 host都是在這裡啟動的:
複製代碼
- protected synchronized void startRouters() throws Exception {
- if (this.internalRouter != null) {
- this.internalRouter.start();
- }
- if (this.defaultHost != null) {
- this.defaultHost.start();
- }
- for (VirtualHost host : getHosts()) {
- host.start();
- }
- }