SpringMVC原始碼解析(一)

2021-10-01 01:57:35 字數 2063 閱讀 3872

我們在web.xml中分別配置了contextloaderlistener和dispatcherservlet:

org.springframework.web.context.contextloaderlistener

contextconfiglocation

spring

org.springframework.web.servlet.dispatcherservlet

contextconfiglocation

/web-inf/springmvc-servlet.xml 1

/

class> contextclass = determinecontextclass(sc); }}

protected class> determinecontextclass(servletcontext servletcontext)

catch (classnotfoundexception ex)

} else

catch (classnotfoundexception ex) }}

//defaultstrategies初始化

static

catch (ioexception ex)

} if (objectutils.identitytostring(wac).equals(wac.getid()))

else

} wac.setservletcontext(sc);

//載入配置資源,對應web.xml的配置

dispatchservlet在初始化過程中,會呼叫父類frameworkservlet的initservletbean()方法,建立spring-mvc的容器並載入bean。我們來看下**的具體如何實現的:

class> contextclass = getcontextclass();

if (this.logger.isdebugenabled())

"fatal initialization error in servlet with name '" + getservletname() +

} wac.setenvironment(getenvironment());

wac.setparent(parent);

wac.setconfiglocation(getcontextconfiglocation());

return wac;

}//重新整理上下文,載入配置的bean

if (objectutils.identitytostring(wac).equals(wac.getid()))

else

} wac.setservletcontext(getservletcontext());

//servletconfig為web.xml中指定的springmvc-servlet.xml

wac.setservletconfig(getservletconfig());

wac.setnamespace(getnamespace());

configurableenvironment env = wac.getenvironment();

if (env instanceof configurablewebenvironment)

wac.refresh();}

SpringMVC頁面訪問流程 原始碼解析

獲取對應的handler介面卡 handleradapter err1 this gethandleradapter gethandler string method request.getmethod boolean isget get equals method if isget head eq...

springmvc原始碼解析 初始化

1.概述 handleradapter的繼承體系 同樣的視 析器viewresolver針對不同的輸出格式也有一系列的實現類,具體可自己看。2.實現分析 以我自己的乙個web專案中spring mvc的配置為例 2.1 spring mvc初始化流程 dispatcherservlet的繼承體系如 ...

SpringMVC原理 解析請求引數(原始碼分析)

在使用springmvc的時候,我們經常編寫controller層的介面,並使用一些註解傳遞一些引數,那麼這些引數是怎麼封裝進我們的請求的呢?springmvc是怎麼解析這些引數的呢?本文主要通過原始碼分析springmvc解析請求引數的全過程。編寫乙個controller類,裡面寫上乙個介面方法 ...