Webx3 初始化過程學習

2021-08-30 18:27:01 字數 4246 閱讀 1921

這兩天利用空餘時間學習了webx3.0,基於spring mvc開發的一款mvc;由於對webx2.0以及spring mvc沒有進行過深入的研究,在學習webx3.0的時候,肯定會出現理解上的偏差甚至錯誤,希望大家積極提出,有問題才是進步的動力;以前很少寫文章,文筆不好,還請大家見諒,:)!無廢話,開始:

web.xml,tomcat載入war包開始:

com.alibaba.citrus.webx.context.webxcontextloaderlistener

其中webxcontextloaderlistener 資訊如下:

import org.springframework.web.context.contextloader;

import org.springframework.web.context.contextloaderlistener;

public class webxcontextloaderlistener extends contextloaderlistener

由於webxcontextloaderlistener覆蓋了createcontextloader()方法,

@override

protected final contextloader createcontextloader()

return defaultcontextclass;}};

}

contextloader已經是這個了:webxcomponentsloader 重點關注這個類,

將負責載入webx中的componet元件,還繼承了spring mvc的載入類 contextloader,

@override

bean***ception

經過自己的init後

又回到父類裡面去了:

throws illegalstateexception, bean***ception

catch (runtimeexception ex)

catch (error err) }

1.找到上下文類

class contextclass = determinecontextclass(servletcontext);
定位上下文class,這個class可配置;這個方法被webxcontextloaderlistener覆蓋,最後返回的class:

return webxcomponentscontext.class;

第二個重要的類出現:webxcomponentscontext

webxcomponentscontext

繼承 繼承

2.例項化上下文類

wac.setparent(parent);

wac.setservletcontext(servletcontext);

wac.setconfiglocation(servletcontext.getinitparameter(config_location_param));

3.可以自定義操作上下文

customizecontext(servletcontext, wac);

//被子類覆蓋

此方法也被webxcontextloaderlistener覆蓋:

this.componentscontext = componentscontext;

if (componentscontext instanceof webxcomponentscontext)

}  

4.初始化ioc容器

wac.refresh();
public void refresh() throws bean***ception, illegalstateexception 

catch (bean***ception ex)

} }

postprocessbeanfactory(beanfactory);有覆蓋嗎?有!

例項化前,webx覆蓋了此方法來,進行把webx元件例項放入spring中,怎麼放?**執行?

((webxcomponentscontext) componentscontext).setloader(this);
這裡看出是webxcomponentsloader來進行這個工作:

/**

* 在建立beanfactory之初被呼叫。

* * @param webxcomponentscontext

*/public void postprocessbeanfactory(configurablelistablebeanfactory beanfactory)

乙個內部類,webxcomponentscreator輔助類就是用來確保初始化順序,見上面:

public static class webxcomponentscreator implements beanfactorypostprocessor, ordered 

public void postprocessbeanfactory(configurablelistablebeanfactory beanfactory) throws bean***ception

}public int getorder()

}

初始化components:

/**

* 初始化components。

*/private webxcomponentsimpl createcomponents(webxconfiguration parentconfiguration,

configurablelistablebeanfactory beanfactory)

// 6.建立並將components物件置入resolvable dependencies,以便注入到需要的bean中

webxcomponentsimpl components = new webxcomponentsimpl(componentscontext, componentsconfig

.getdefaultcomponent(), rootcontroller, parentconfiguration);

beanfactory.registerresolvabledependency(webxcomponents.class, components);

// 7.初始化每個component

for (string componentname : componentnames)

if (controller == null)

webxcomponentimpl component = new webxcomponentimpl(components, componentname, componentpath, componentname

.equals(componentsconfig.getdefaultcomponent()), controller, getwebxconfigurationname());

components.addcomponent(component);

preparecomponent(component, componentnamesandlocations.get(componentname));

}return components;

}

怎麼找到components,只要找到對應配置項即可

public string getcomponentconfigurationlocationpattern() 

//找到了配置檔案,接下去要解析了,裡面實現比較囉嗦,@#¥#@¥@#¥一大堆,返回

未完待續......

學習了webx3.0和spring mvc如何結果工作,對於定製web mvc有幫助!

類初始化和例項初始化過程

類初始化過程 乙個類要建立例項需要先載入並初始化該類 main方法所在的類需要先載入和初始化 乙個子類要初始化需要先初始化父類 乙個類初始化就是執行 方法 由靜態類變數賦值 和靜態 塊組成 靜態類變數賦值 和靜態 塊從上往下執行 方法只執行一次 例項初始化過程 例項初始化就是執行 方法 方法可能過載...

記憶體初始化過程

1,物理記憶體資訊的獲取 0x15中斷,功能號 e820h,e801h,e88h 見檔案 linux arch i386 boot setup.s 執行完上面的 後,記憶體資訊被分為多條資訊放在e820map位置處,每個資訊條目長20位元組,包含乙個記憶體區間的資訊,條目數放在e820nr處。即實際...

Struts初始化過程

sturts初始化過程取決於在web.xml檔案中配置的初始化引數,servlet容器在首次啟動或servlet的第一次請求到達時載入struts actionservlet。在這兩種情況下,要保證init 方法被呼叫,並且必須在servlet處理任何請求之前完成。當init 被呼叫時,struts...