关闭

共同学习SpringMVC源码--DispatcherServlet(一)

286人阅读 评论(0) 收藏 举报
分类:

public class DispatcherServlet extends FrameworkServlet

这是类签名,继承自FrameworkServlet。我会抽出篇幅来介绍这个父类。

/** Well-known name for the MultipartResolver object in the bean factory for this namespace. */
public static final String MULTIPART_RESOLVER_BEAN_NAME = "multipartResolver";
/** Well-known name for the LocaleResolver object in the bean factory for this namespace. */
public static final String LOCALE_RESOLVER_BEAN_NAME = "localeResolver";
/** Well-known name for the ThemeResolver object in the bean factory for this namespace. */
public static final String THEME_RESOLVER_BEAN_NAME = "themeResolver";
/**
* Well-known name for the HandlerMapping object in the bean factory for this namespace.
* Only used when "detectAllHandlerMappings" is turned off.
* @see #setDetectAllHandlerMappings
*/
public static final String HANDLER_MAPPING_BEAN_NAME = "handlerMapping";
/**
* Well-known name for the HandlerAdapter object in the bean factory for this namespace.
* Only used when "detectAllHandlerAdapters" is turned off.
* @see #setDetectAllHandlerAdapters
*/
public static final String HANDLER_ADAPTER_BEAN_NAME = "handlerAdapter";
/**
* Well-known name for the HandlerExceptionResolver object in the bean factory for this namespace.
* Only used when "detectAllHandlerExceptionResolvers" is turned off.
* @see #setDetectAllHandlerExceptionResolvers
*/
public static final String HANDLER_EXCEPTION_RESOLVER_BEAN_NAME = "handlerExceptionResolver";
/**
* Well-known name for the RequestToViewNameTranslator object in the bean factory for this namespace.
*/
public static final String REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME = "viewNameTranslator";
/**
* Well-known name for the ViewResolver object in the bean factory for this namespace.
* Only used when "detectAllViewResolvers" is turned off.
* @see #setDetectAllViewResolvers
*/
public static final String VIEW_RESOLVER_BEAN_NAME = "viewResolver";
/**
* Well-known name for the FlashMapManager object in the bean factory for this namespace.
*/
public static final String FLASH_MAP_MANAGER_BEAN_NAME = "flashMapManager";

以上这些静态final的字符串成员变量都是各种bean的名称。
/**
* Request attribute to hold the current web application context.
* Otherwise only the global web app context is obtainable by tags etc.
* @see org.springframework.web.servlet.support.RequestContextUtils#findWebApplicationContext
*/
public static final String WEB_APPLICATION_CONTEXT_ATTRIBUTE = DispatcherServlet.class.getName() + ".CONTEXT";
/**
* Request attribute to hold the current LocaleResolver, retrievable by views.
* @see org.springframework.web.servlet.support.RequestContextUtils#getLocaleResolver
*/
public static final String LOCALE_RESOLVER_ATTRIBUTE = DispatcherServlet.class.getName() + ".LOCALE_RESOLVER";
/**
* Request attribute to hold the current ThemeResolver, retrievable by views.
* @see org.springframework.web.servlet.support.RequestContextUtils#getThemeResolver
*/
public static final String THEME_RESOLVER_ATTRIBUTE = DispatcherServlet.class.getName() + ".THEME_RESOLVER";
/**
* Request attribute to hold the current ThemeSource, retrievable by views.
* @see org.springframework.web.servlet.support.RequestContextUtils#getThemeSource
*/
public static final String THEME_SOURCE_ATTRIBUTE = DispatcherServlet.class.getName() + ".THEME_SOURCE";
/**
* Name of request attribute that holds a read-only {@code Map<String,?>}
* with "input" flash attributes saved by a previous request, if any.
* @see org.springframework.web.servlet.support.RequestContextUtils#getInputFlashMap(HttpServletRequest)
*/
public static final String INPUT_FLASH_MAP_ATTRIBUTE = DispatcherServlet.class.getName() + ".INPUT_FLASH_MAP";
/**
* Name of request attribute that holds the "output" {@link FlashMap} with
* attributes to save for a subsequent request.
* @see org.springframework.web.servlet.support.RequestContextUtils#getOutputFlashMap(HttpServletRequest)
*/
public static final String OUTPUT_FLASH_MAP_ATTRIBUTE = DispatcherServlet.class.getName() + ".OUTPUT_FLASH_MAP";
/**
* Name of request attribute that holds the {@link FlashMapManager}.
* @see org.springframework.web.servlet.support.RequestContextUtils#getFlashMapManager(HttpServletRequest)
*/
public static final String FLASH_MAP_MANAGER_ATTRIBUTE = DispatcherServlet.class.getName() + ".FLASH_MAP_MANAGER";
/**
* Name of request attribute that exposes an Exception resolved with an
* {@link HandlerExceptionResolver} but where no view was rendered
* (e.g. setting the status code).
*/
public static final String EXCEPTION_ATTRIBUTE = DispatcherServlet.class.getName() + ".EXCEPTION";

以上这些静态final的字符串成员变量是各种属性名。
/** Log category to use when no mapped handler is found for a request. */
public static final String PAGE_NOT_FOUND_LOG_CATEGORY = "org.springframework.web.servlet.PageNotFound";

这个静态final的字符串属性实际上就是在请求找不到资源时打印出来的字符串。
/**
* Name of the class path resource (relative to the DispatcherServlet class)
* that defines DispatcherServlet's default strategy names.
*/
private static final String DEFAULT_STRATEGIES_PATH = "DispatcherServlet.properties";
这个静态final的字符串属性是配置文件名,该配置文件在同一包下,也就是这个包org.springframework.web.servlet
/** Additional logger to use when no mapped handler is found for a request. */
protected static final Log pageNotFoundLogger = LogFactory.getLog(PAGE_NOT_FOUND_LOG_CATEGORY);

这个静态final的Log对象是请求找不到匹配的handler时的日志工具,将上面那个变量传入,以便在找不到资源时打印出相应字符串。

0
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

SpringMVC工作原理解读--DispatcherServlet类源码解读(初级)

我这里先通读一下DispatcherServlet的代码,首先知道各个部分是什么用处,后面再次进行串联的讲解。一开始我可能也讲的不是很明白,但是时间久了我觉得自然而然的就明白了。读者可以发布自己的意见...
  • wangyang1354
  • wangyang1354
  • 2016-07-22 22:18
  • 2629

SpringMVC源码深度分析DispatcherServlet核心的控制器(初始化)

SpringMVC是非常优秀的MVC框架,每个框架都是为了我们提高开发效率,我们试图通过对SpringMVC的源代码去了解这个框架,了解整个设计思想,框架要有扩展性,这里用的比较多是接口和抽象,是框架...
  • congcong68
  • congcong68
  • 2014-10-25 11:29
  • 4351

SpringMVC源码剖析(四)- DispatcherServlet请求转发的实现

SpringMVC完成初始化流程之后,就进入Servlet标准生命周期的第二个阶段,即“service”阶段。在“service”阶段中,每一次Http请求到来,容器都会启动一个请求线程,通过serv...
  • luqin1988
  • luqin1988
  • 2013-06-03 17:33
  • 4593

SpringMVC源码之解读DispatcherServlet初始化流程

SpringMVC的配置流程并不复杂,但每个步骤所涉及的东西比较多,一不小心配错可就糟糕了。但这参与感十足的配置方式除了它的灵活性外,也能让我们更加清楚框架在为我们服务之前,到底做了哪些事情,接下来我...
  • Roderick2015
  • Roderick2015
  • 2016-10-18 09:52
  • 1062

springMVC源码分析--DispatcherServlet请求获取及处理

在之前的博客 springMVC源码分析--容器初始化(二)DispatcherServlet中我们介绍过DispatcherServlet,是在容器初始化过程中出现的,我们之前也说过Dispatch...
  • qq924862077
  • qq924862077
  • 2016-12-08 20:38
  • 1230

Spring MVC 原理 - DispatcherServlet调用完整过程(上)

进入web.xml中配置的Spring拦截(调度)器:   调用堆栈信息: 开始拦截,这一步主要是根据request获取handler(该handler可以配置): (接上面方法)这...
  • isea533
  • isea533
  • 2014-03-10 21:03
  • 14332

Spring 源码解析之DispatcherServlet源码解析(五)

Spring 源码解析之DispatcherServlet源码解析(五)前言 本文需要有前四篇文章的基础,才能够清晰易懂,有兴趣可以先看看详细的流程,这篇文章可以说是第一篇文章,也可以说是前四篇文...
  • veZunShao
  • veZunShao
  • 2016-05-30 22:27
  • 5922

Spring源码分析: SpringMVC启动流程与DispatcherServlet请求处理流程

Spring版本: 4.0.X 注:这里的分析只关注整个处理流程的大致过程,省略与流程无关的代码。应用根上下文(Root ApplicationContext)的启动在一个web项目中使用Sprin...
  • tracker_w
  • tracker_w
  • 2015-03-11 23:54
  • 1829

springmvc学习笔记(20)-拦截器

本文主要介绍springmvc中的拦截器,包括拦截器定义和的配置,然后演示了一个链式拦截的测试示例,最后通过一个登录认证的例子展示了拦截器的应用
  • h3243212
  • h3243212
  • 2016-03-15 11:29
  • 4404

通过配置多个DispatcherServlet解决SpringMVC RESTAPI前后端分离资源访问的问题

起因Spring MVC项目需要前后端分离,REST API 和 静态资源 需要走不同的DispatcherServlet。
  • u013363449
  • u013363449
  • 2016-03-27 15:03
  • 4373
    个人资料
    • 访问:46742次
    • 积分:2119
    • 等级:
    • 排名:千里之外
    • 原创:168篇
    • 转载:0篇
    • 译文:0篇
    • 评论:15条
    文章分类
    最新评论