SpringMVC框架設計原理與實現
一、SpringMVC框架是什麼
springmvc是一套封裝網路請求的半封裝Servlet框架,是站在巨人肩膀(JDK javax.servlet.*)上做下層
類的結構圖:
二、Servlet規範
開發的時候讀取很多專案原始碼部署--->肯定存在Servlet規範
SpringMVC框架就是以Servlet服務形式掛在web.xml當中被容器讀取
web.xml配置:
<!--SpringMVC前端控制器-->
<servlet>
<servlet-name>SpringMVC</servlet-name>
<servlet-class>org.springframework.web</servlet-class>
<!--servlet範圍內引數,只能在servlet的init()方法中獲取,在web.xml配置中如下-->
<init-param>
<description>:contextConfigLocation標識用於載入bean的配置檔案</description>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:conf/spring/spring_mvc.xml</param-value>
</init-param>
<!--表示啟動容器時初始化該servlet-->
<load-on-startup>1</load-on-startup>
</servlet>
三、SpringMVC和Tomcat的關係
四、SpringMVC的上下文
執行SpringMVC專案底層Bean元件(基礎)支援體系(環境支援)
SpringMVC進行業務處理的時候構建一個Application,接受網路層請求的時候都需要它
業務邏輯處理層必須使用到的元件都封裝在上下文中,由上下文來“介紹”
五、SpringMVC框架處理請求業務流程
第一步:javax.servlet.Servlet.HttpServlet.service()方法——請求方法型別轉向分發————》
第二步:org.springframework.web.servlet.FrameworkServlet.service()方法————————》
第三步:avax.servlet.Servlet.servlet.service()方法————當中的處理常規的7種請求型別————》
第四步:org.springframework.web.servlet.FrameworkServlet.processRequest(HttpServletRequest request,HttpServletResponse response)方法——————————》
第五步:org.springframework.web.servlet.DispatcherServlet.doService()方法————————》
第六步:org.springframework.web.servlet.DispatcherServlet.doDispatcher———》真正的多業務處理
手寫自己的SpringMVC的框架--設計思路
總結:為什麼業務離不來WebApplicationContext-----WebApplicationContext存活在容器的上下文中