Special Bean Types In the WebApplicationContext

解读

1.WebApplicationContext 特有的几种 Bean Types

2. 也表明 与之相对的 还有 ApplicationContext

下面这几种特有的 web bean types 也理应定义到 web 的上下文配置文件中,比如 a-servlet.xml

Table 22.1. Special bean types in the WebApplicationContext

Bean type Explanation

HandlerMapping

Maps incoming requests to handlers and a list of pre- and post-processors (handler interceptors) based on some criteria the details of which vary by HandlerMapping implementation. The most popular implementation supports annotated controllers but other implementations exists as well.

HandlerAdapter

Helps the DispatcherServlet to invoke a handler mapped to a request regardless of the handler is actually invoked. For example, invoking an annotated controller requires resolving various annotations. Thus the main purpose of aHandlerAdapter is to shield the DispatcherServlet from such details.

HandlerExceptionResolver

Maps exceptions to views also allowing for more complex exception handling code.

ViewResolver

Resolves logical String-based view names to actual View types.

LocaleResolver &LocaleContextResolver

Resolves the locale a client is using and possibly their time zone, in order to be able to offer internationalized views

ThemeResolver

Resolves themes your web application can use, for example, to offer personalized layouts

MultipartResolver

Parses multi-part requests for example to support processing file uploads from HTML forms.

FlashMapManager

Stores and retrieves the "input" and the "output" FlashMap that can be used to pass attributes from one request to another, usually across a redirect.

查看dispatcherServlet 相关日志

  1. Line 2: 2016-10-04 13:07:57 DEBUG DispatcherServlet:118 - Initializing servlet 'dispatcher'
  2. Line 9: 2016-10-04 13:07:57 INFO DispatcherServlet:489 - FrameworkServlet 'dispatcher': initialization started
  3. Line 10: 2016-10-04 13:07:57 DEBUG DispatcherServlet:617 - Servlet with name 'dispatcher' will try to create custom WebApplicationContext context of class 'org.springframework.web.context.support.XmlWebApplicationContext', using parent context [null]
  4. Line 577: 2016-10-04 13:07:59 DEBUG DispatcherServlet:511 - Unable to locate MultipartResolver with name 'multipartResolver': no multipart request handling provided
  5. Line 586: 2016-10-04 13:07:59 DEBUG DispatcherServlet:533 - Unable to locate LocaleResolver with name 'localeResolver': using default [org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver@3af54caa]
  6. Line 594: 2016-10-04 13:07:59 DEBUG DispatcherServlet:555 - Unable to locate ThemeResolver with name 'themeResolver': using default [org.springframework.web.servlet.theme.FixedThemeResolver@1508dd9]
  7. Line 619: 2016-10-04 13:07:59 DEBUG DispatcherServlet:692 - Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@4a233666]
  8. Line 629: 2016-10-04 13:07:59 DEBUG DispatcherServlet:753 - Unable to locate FlashMapManager with name 'flashMapManager': using default [org.springframework.web.servlet.support.SessionFlashMapManager@2c267a73]
  9. Line 643: 2016-10-04 13:07:59 DEBUG DispatcherServlet:568 - Published WebApplicationContext of servlet 'dispatcher' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher]
  10. Line 644: 2016-10-04 13:07:59 INFO DispatcherServlet:508 - FrameworkServlet 'dispatcher': initialization completed in 1538 ms
  11. Line 645: 2016-10-04 13:07:59 DEBUG DispatcherServlet:139 - Servlet 'dispatcher' configured successfully

dispatcherServlet 干了什么

1. 设置默认的策略(位于DispatcherServlet.properties 中)

  1. static {
  2. // Load default strategy implementations from properties file.
  3. // This is currently strictly internal and not meant to be customized
  4. // by application developers.
  5. try {
  6. ClassPathResource resource = new ClassPathResource(DEFAULT_STRATEGIES_PATH, DispatcherServlet.class);
  7. defaultStrategies = PropertiesLoaderUtils.loadProperties(resource);
  8. }
  9. catch (IOException ex) {
  10. throw new IllegalStateException("Could not load 'DispatcherServlet.properties': " + ex.getMessage());
  11. }
  12. }
  1. # Default implementation classes for DispatcherServlet's strategy interfaces.
  2. # Used as fallback when no matching beans are found in the DispatcherServlet context.
  3. # Not meant to be customized by application developers.
  4.  
  5. org.springframework.web.servlet.LocaleResolver=org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver
  6.  
  7. org.springframework.web.servlet.ThemeResolver=org.springframework.web.servlet.theme.FixedThemeResolver
  8.  
  9. org.springframework.web.servlet.HandlerMapping=org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,\
  10. org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping
  11.  
  12. org.springframework.web.servlet.HandlerAdapter=org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,\
  13. org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,\
  14. org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
  15.  
  16. org.springframework.web.servlet.HandlerExceptionResolver=org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver,\
  17. org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver,\
  18. org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver
  19.  
  20. org.springframework.web.servlet.RequestToViewNameTranslator=org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator
  21.  
  22. org.springframework.web.servlet.ViewResolver=org.springframework.web.servlet.view.InternalResourceViewResolver

DispatcherServlet.properties

2. 初始化

  1. protected void initStrategies(ApplicationContext context) {
  2. initMultipartResolver(context);
  3. initLocaleResolver(context);
  4. initThemeResolver(context);
  5. initHandlerMappings(context);
  6. initHandlerAdapters(context);
  7. initHandlerExceptionResolvers(context);
  8. initRequestToViewNameTranslator(context);
  9. initViewResolvers(context);
  10. }

举例来说就是存在指定的就用指定的,不存在指定的就用默认的

  1. private void initRequestToViewNameTranslator(ApplicationContext context) {
  2. try {
  3. this.viewNameTranslator =
  4. context.getBean(REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME, RequestToViewNameTranslator.class);
  5. if (logger.isDebugEnabled()) {
  6. logger.debug("Using RequestToViewNameTranslator [" + this.viewNameTranslator + "]");
  7. }
  8. }
  9. catch (NoSuchBeanDefinitionException ex) {
  10. // We need to use the default.
  11. this.viewNameTranslator = getDefaultStrategy(context, RequestToViewNameTranslator.class);
  12. if (logger.isDebugEnabled()) {
  13. logger.debug("Unable to locate RequestToViewNameTranslator with name '" +
  14. REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME + "': using default [" + this.viewNameTranslator +
  15. "]");
  16. }
  17. }
  18. }

这便是上面的日志的原因

Spring MVC 指导文档解读(二)的更多相关文章

  1. Spring MVC 指导文档解读(一)

    22.1 指导文档章节 In the Web MVC framework, each DispatcherServlet has its own WebApplicationContext, whic ...

  2. Android BLE与终端通信(五)——Google API BLE4.0低功耗蓝牙文档解读之案例初探

    Android BLE与终端通信(五)--Google API BLE4.0低功耗蓝牙文档解读之案例初探 算下来很久没有写BLE的博文了,上家的技术都快忘记了,所以赶紧读了一遍Google的API顺便 ...

  3. 部署openstack的官网文档解读mysql的配置文件

    部署openstack的官网文档解读mysql的配置文件(使用与ubutu和centos7等系统) author:headsen chen  2017-10-12 16:57:11 个人原创,严禁转载 ...

  4. MSDN 单机 MVC 帮助文档

    因为微软的mvc框架也是从开源框架演变而来的,所以微软没把mvc帮助文档放到单击帮助文档中.sososos下载好msdn单机帮助后,却找不到 System.Web.MVC 等命名空间的东西. 解决办法 ...

  5. 【Java架构:基础技术】一篇文章搞掂:Spring Boot 官方文档解读

    本文篇幅较长,建议合理利用右上角目录进行查看(如果没有目录请刷新). 本文内容大部分是翻译和总结官方文档,可以到https://docs.spring.io/spring-boot/docs查看(此地 ...

  6. 集成 Spring Doc 接口文档和 knife4j-SpringBoot 2.7.2 实战基础

    优雅哥 SpringBoot 2.7.2 实战基础 - 04 -集成 Spring Doc 接口文档和 knife4j 前面已经集成 MyBatis Plus.Druid 数据源,开发了 5 个接口. ...

  7. Spring学习----- Spring配置文件xml文档的schema约束

    1.配置文件示例. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...

  8. 关于Spring配置文件xml文档的schema约束

    最开始使用spring框架的时候,对于其配置文件xml,只是网上得知其使用方法,而不明其意.最近想着寻根问底的探究一下.以下是本文主要内容: 1.配置文件示例. <?xml version=&q ...

  9. Spring中xml文档的schema约束

    最开始使用Spring框架的时候,对于其配置文件xml,只是网上得知其使用方法,而不明其意.最近想着寻根问底的探究一下.以下是本文主要内容: 1.配置文件示例.   <?xml version= ...

随机推荐

  1. JQuery UI之Autocomplete(4)多值输入、远程缓存与组合框

    1.多值输入 首先加入相关的css和js文件,以及对应的HTML代码如下: <link href="../css/jquery-ui.css" rel="style ...

  2. export命令

    http://blog.csdn.net/wl_fln/article/details/7258294 http://man.linuxde.net/export export命令 功能说明:设置或显 ...

  3. 使用json要导入什么包

    json-lib-2.3-jdk15.jar commons-beanutils-1.7.0.jar commons-httpclient-3.1.jar commons-lang-2.3.jar c ...

  4. JS获取Dropdownlist选中值

    var dropDownList = document.getElementById("ddl_sheng"); //获取DropDownList控件 var dropDownLi ...

  5. UML 图C#

    继承关系(类1继承类2) 代码: class Class1:Class2 { } class Class2 { } 实现(实现接口) 代码: interface interface1 { void s ...

  6. Android开发之利用ViewPager实现在Activity或Fragment中引入别的布局文件实现滑动并进行页面跳转

    有些时候经常可以看到其他APP中有一排的图标,可以在一个界面中滑来滑去,并且图标可以进行点击事件进行页面的跳转.这里对这种方法的实现做出总结. 首先看一下图片: 下面这两种图片是在一个Fragment ...

  7. linux网卡绑定脚本

    2013-08-20 15:30:51 此脚本适用于CentOS5.x和CentOS6.x. #!/bin/bash #**************************************** ...

  8. 关于python的字符编码

    理论特别多,金角大王讲的非常细致和深入浅出. 我来个简短的总结: python2的编码:默认是ascii,可以改变成gbk,utf-8等,但是用什么编码写的,就存储成什么编码.如果搬到linux,默认 ...

  9. python提取百度经验<标题,发布时间,平均流量,总流量,具体的链接>

    之前想研究下怎么抓网页数据.然后就有了下面的练习了. 如有BUG.也纯属正常. 只是练习.请勿投入产品使用. #!/usr/bin/python # -*- coding: utf-8 -*- #Fi ...

  10. 让eclipse调试和豌豆荚并存

    豌豆荚有一个设置 设置->高级设置->开发者模式 勾上开发者模式 确定. 你什么手机的驱动都不用安装了. 就可以直接使用豌豆荚,也可以使用eclipse进行调试.