第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

Spring父容器與Spring MVC子容器是如何體現(xiàn)出父子關(guān)系的

Spring父容器與Spring MVC子容器是如何體現(xiàn)出父子關(guān)系的

Qyouu 2019-05-12 13:50:50
平常的子類繼承父類通過extends關(guān)鍵字來實(shí)現(xiàn),那么Spring父容器與SpringMVC子容器是如何體現(xiàn)出父子關(guān)系的呢?容器指的是一個(gè)類嗎?Spring容器是哪個(gè)類,SpringMVC容器又是哪個(gè)類?
查看完整描述

2 回答

?
哈士奇WWW

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超6個(gè)贊

所謂容器,就是上下文,在這同一個(gè)上下文里,大家可以共享一些東西。
在Spring應(yīng)用啟動時(shí),會先讀取web.xml文件,調(diào)用ContextLoaderListener創(chuàng)建Spring容器,也就是你說的父容器。
org.springframework.web.context.ContextLoaderListener
Listener創(chuàng)建完之后,開始創(chuàng)建Servlet:
SpringMVC
org.springframework.web.servlet.DispatcherServlet
這時(shí)候這個(gè)DispatcherServlet開始試圖創(chuàng)建SpringMVC的ApplicationContext,它先找剛才由上面那個(gè)ContextLoaderListener創(chuàng)建的Spring的ApplicationContext,找到后,把Spring的ApplicationContext作為參數(shù)傳給DispatcherServlet的ApplicationContext的setParent方法,這樣SpringMVC的容器就變成了Spring容器的兒子。
因?yàn)樵赟pringMVC這個(gè)子容器創(chuàng)建的時(shí)候指定了它的Spring父容器,所以兒子能找到父親,所以SpringMVC這個(gè)子容器里的Bean可以調(diào)用父容器的服務(wù),而父容器不知道有這個(gè)兒子的存在(一個(gè)不負(fù)責(zé)任的父親),父容器里的Bean不能調(diào)用子容器里的服務(wù)。
                            
查看完整回答
反對 回復(fù) 2019-05-12
?
手掌心

TA貢獻(xiàn)1942條經(jīng)驗(yàn) 獲得超3個(gè)贊

想必Servlet的關(guān)系就不必多說了,直接上代碼吧HttpServletBean繼承了HttpServlet,init方法如下
@Override
publicfinalvoidinit()throwsServletException{
//Letsubclassesdowhateverinitializationtheylike.
initServletBean();
}
看看子類FrameworkServlet#initServletBean方法
@Override
protectedfinalvoidinitServletBean()throwsServletException{
this.webApplicationContext=initWebApplicationContext();
initFrameworkServlet();
}
看看initWebApplicationContext
protectedWebApplicationContextinitWebApplicationContext(){
WebApplicationContextrootContext=WebApplicationContextUtils.getWebApplicationContext(getServletContext());
WebApplicationContextwac=null;
if(this.webApplicationContext!=null){
wac=this.webApplicationContext;
if(wacinstanceofConfigurableWebApplicationContext){
ConfigurableWebApplicationContextcwac=(ConfigurableWebApplicationContext)wac;
if(!cwac.isActive()){
//Thecontexthasnotyetbeenrefreshed->provideservicessuchas
//settingtheparentcontext,settingtheapplicationcontextid,etc
if(cwac.getParent()==null){
//Thecontextinstancewasinjectedwithoutanexplicitparent->set
//therootapplicationcontext(ifany;maybenull)astheparent,看到?jīng)]有,如果有就設(shè)置rootApplicationContext,
cwac.setParent(rootContext);
}
configureAndRefreshWebApplicationContext(cwac);
}
}
}
if(wac==null){
//Nocontextinstancewasinjectedatconstructiontime->seeifone
//hasbeenregisteredintheservletcontext.Ifoneexists,itisassumed
//thattheparentcontext(ifany)hasalreadybeensetandthatthe
//userhasperformedanyinitializationsuchassettingthecontextid
wac=findWebApplicationContext();
}
if(wac==null){
//Nocontextinstanceisdefinedforthisservlet->createalocalone
wac=createWebApplicationContext(rootContext);
}
if(!this.refreshEventReceived){
//EitherthecontextisnotaConfigurableApplicationContextwithrefresh
//supportorthecontextinjectedatconstructiontimehadalreadybeen
//refreshed->triggerinitialonRefreshmanuallyhere.看到這里就不多說了,初始化beanFactory
onRefresh(wac);
}
if(this.publishContext){
StringattrName=getServletContextAttributeName();
getServletContext().setAttribute(attrName,wac);
}
returnwac;
}
結(jié)束,就是辣么簡單
                            
查看完整回答
反對 回復(fù) 2019-05-12
  • 2 回答
  • 0 關(guān)注
  • 476 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號