最近对spring兴趣高涨,刚好,一个SSI框架的项目落地,空闲一段时间,索性看看spring mvc.
Spring mvc请求调用模型

一。spring mvc 的配置起点 - web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3.1.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<!-- Spring ApplicationContext配置文件的路径,可使用通配符,多个路径用","号分隔 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!--Spring ApplicationContext 载入 -->
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>spring_mvc_xml.root</param-value>
</context-param>
<!-- 开一条watchdog线程每3秒扫描一下配置文件的变化; -->
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>3000</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<servlet>
<servlet-name>webUrl</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/com/wsg/conf/web/webUrl-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 拦截所有以do结尾的请求 -->
<servlet-mapping>
<servlet-name>webUrl</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
作为项目初始化的第一步,在springMVC架构中最主要的两点:
1.ContextLoaderListener
该监听器主要负责整个项目根上下文的初始化,并保存至ServletContext,建立整个项目的ioc体系。
其中的初始化流程如下图:

2.DispatcherServlet
该servlet配置主要负责spring mvc里的子上下文的初始化。
包括相应的MVC bean对象:
国际化支持:LocalResolver
request映射:HandlerMappings
返回视图的生成:Viewresolver
等 。。。。。。。
初始化流程如图:

SpringMVC配置解析
本文详细介绍了SpringMVC的配置过程,重点讲述了web.xml中关键元素的作用,包括ContextLoaderListener和DispatcherServlet的初始化流程,以及如何配置servlet-mapping来处理特定URL请求。

被折叠的 条评论
为什么被折叠?



