Spring MVC 指导文档解读(二)
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 |
---|---|
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 |
|
HandlerAdapter |
Helps the |
Maps exceptions to views also allowing for more complex exception handling code. |
|
Resolves logical String-based view names to actual |
|
Resolves the locale a client is using and possibly their time zone, in order to be able to offer internationalized views |
|
Resolves themes your web application can use, for example, to offer personalized layouts |
|
Parses multi-part requests for example to support processing file uploads from HTML forms. |
|
Stores and retrieves the "input" and the "output" |
查看dispatcherServlet 相关日志
Line 2: 2016-10-04 13:07:57 DEBUG DispatcherServlet:118 - Initializing servlet 'dispatcher'
Line 9: 2016-10-04 13:07:57 INFO DispatcherServlet:489 - FrameworkServlet 'dispatcher': initialization started
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]
Line 577: 2016-10-04 13:07:59 DEBUG DispatcherServlet:511 - Unable to locate MultipartResolver with name 'multipartResolver': no multipart request handling provided
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]
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]
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]
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]
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]
Line 644: 2016-10-04 13:07:59 INFO DispatcherServlet:508 - FrameworkServlet 'dispatcher': initialization completed in 1538 ms
Line 645: 2016-10-04 13:07:59 DEBUG DispatcherServlet:139 - Servlet 'dispatcher' configured successfully
dispatcherServlet 干了什么
1. 设置默认的策略(位于DispatcherServlet.properties 中)
static {
// Load default strategy implementations from properties file.
// This is currently strictly internal and not meant to be customized
// by application developers.
try {
ClassPathResource resource = new ClassPathResource(DEFAULT_STRATEGIES_PATH, DispatcherServlet.class);
defaultStrategies = PropertiesLoaderUtils.loadProperties(resource);
}
catch (IOException ex) {
throw new IllegalStateException("Could not load 'DispatcherServlet.properties': " + ex.getMessage());
}
}
# Default implementation classes for DispatcherServlet's strategy interfaces.
# Used as fallback when no matching beans are found in the DispatcherServlet context.
# Not meant to be customized by application developers. org.springframework.web.servlet.LocaleResolver=org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver org.springframework.web.servlet.ThemeResolver=org.springframework.web.servlet.theme.FixedThemeResolver org.springframework.web.servlet.HandlerMapping=org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,\
org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping org.springframework.web.servlet.HandlerAdapter=org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,\
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,\
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter org.springframework.web.servlet.HandlerExceptionResolver=org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver,\
org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver,\
org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver org.springframework.web.servlet.RequestToViewNameTranslator=org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator org.springframework.web.servlet.ViewResolver=org.springframework.web.servlet.view.InternalResourceViewResolver
DispatcherServlet.properties
2. 初始化
protected void initStrategies(ApplicationContext context) {
initMultipartResolver(context);
initLocaleResolver(context);
initThemeResolver(context);
initHandlerMappings(context);
initHandlerAdapters(context);
initHandlerExceptionResolvers(context);
initRequestToViewNameTranslator(context);
initViewResolvers(context);
}
举例来说就是存在指定的就用指定的,不存在指定的就用默认的
private void initRequestToViewNameTranslator(ApplicationContext context) {
try {
this.viewNameTranslator =
context.getBean(REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME, RequestToViewNameTranslator.class);
if (logger.isDebugEnabled()) {
logger.debug("Using RequestToViewNameTranslator [" + this.viewNameTranslator + "]");
}
}
catch (NoSuchBeanDefinitionException ex) {
// We need to use the default.
this.viewNameTranslator = getDefaultStrategy(context, RequestToViewNameTranslator.class);
if (logger.isDebugEnabled()) {
logger.debug("Unable to locate RequestToViewNameTranslator with name '" +
REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME + "': using default [" + this.viewNameTranslator +
"]");
}
}
}
这便是上面的日志的原因
Spring MVC 指导文档解读(二)的更多相关文章
- Spring MVC 指导文档解读(一)
22.1 指导文档章节 In the Web MVC framework, each DispatcherServlet has its own WebApplicationContext, whic ...
- Android BLE与终端通信(五)——Google API BLE4.0低功耗蓝牙文档解读之案例初探
Android BLE与终端通信(五)--Google API BLE4.0低功耗蓝牙文档解读之案例初探 算下来很久没有写BLE的博文了,上家的技术都快忘记了,所以赶紧读了一遍Google的API顺便 ...
- 部署openstack的官网文档解读mysql的配置文件
部署openstack的官网文档解读mysql的配置文件(使用与ubutu和centos7等系统) author:headsen chen 2017-10-12 16:57:11 个人原创,严禁转载 ...
- MSDN 单机 MVC 帮助文档
因为微软的mvc框架也是从开源框架演变而来的,所以微软没把mvc帮助文档放到单击帮助文档中.sososos下载好msdn单机帮助后,却找不到 System.Web.MVC 等命名空间的东西. 解决办法 ...
- 【Java架构:基础技术】一篇文章搞掂:Spring Boot 官方文档解读
本文篇幅较长,建议合理利用右上角目录进行查看(如果没有目录请刷新). 本文内容大部分是翻译和总结官方文档,可以到https://docs.spring.io/spring-boot/docs查看(此地 ...
- 集成 Spring Doc 接口文档和 knife4j-SpringBoot 2.7.2 实战基础
优雅哥 SpringBoot 2.7.2 实战基础 - 04 -集成 Spring Doc 接口文档和 knife4j 前面已经集成 MyBatis Plus.Druid 数据源,开发了 5 个接口. ...
- Spring学习----- Spring配置文件xml文档的schema约束
1.配置文件示例. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="htt ...
- 关于Spring配置文件xml文档的schema约束
最开始使用spring框架的时候,对于其配置文件xml,只是网上得知其使用方法,而不明其意.最近想着寻根问底的探究一下.以下是本文主要内容: 1.配置文件示例. <?xml version=&q ...
- Spring中xml文档的schema约束
最开始使用Spring框架的时候,对于其配置文件xml,只是网上得知其使用方法,而不明其意.最近想着寻根问底的探究一下.以下是本文主要内容: 1.配置文件示例. <?xml version= ...
随机推荐
- 微信小程序中用setData修改一个对象的属性值
原创文章 1. Page({ data: { items:{ //items为一个对象,is_like和like分别为其两个属性 is_like: 0, like: 0 ...
- __block的初步用法
再block中使用 self 时,要在前面加上__block. 防止在block中用到self时把self对象retain, 造成内存泄露. __block UIViewController *saf ...
- ROS与深度相机入门教程-在ROS使用kinect v1摄像头
ROS与深度相机入门教程-在ROS使用kinect v1摄像头 说明: 介绍在ros安装和使用kinect v1摄像头 介绍freenect包 安装驱动 deb安装 $ sudo apt-get in ...
- props传递数据
一.传递数据 1.props 传入单数据 就像 data 一样,prop 可以用在模板内,同样也可以在 vm 实例中像“this.message”这样使用 <template> <d ...
- CSS-解决苹果点击高亮、安卓select灰色背景(select下拉框在IOS中背景变黑、出现阴影问题)
1.在苹果手机上,用点击事件后会出现一个高亮的阴影: 面对click事件的阴影,解决办法: *{ -webkit-tap-highlight-color: rgba(0,0,0,0); -webkit ...
- ef linq 中判断实体中是否包含某集合
我有一个需求,问题有很多标签,在查询时,需要筛选包含查询标签的一个集合(List<int>),以前的做法是先查询出来符合查询标签条件的标签id的结果集A,再查询问题时,加上判断是否包含该标 ...
- 对于devexpress gridview 内插图加加进度条等的一点解读
如上图,gategory 加了小图标, 其他行内还有计算器,大图片 进度条等 using System; using System.Drawing; using System.Collection ...
- EmguCV Image类中的函数(二)使用MorphologyEx进行更多的变换
MorphologyEx中所有的变换如下图所示 调用方法: Mat aaa = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.R ...
- Oracle to_char函数的使用方法
Oracle to_char函数的功能是将数值型或者日期型转化为字符型,下面就为您详细介绍Oracle to_char函数的使用,希望对您能有所帮助. Postgres 格式化函数提供一套有效的工具用 ...
- Android开发颜色大全
<!-- dialog背景颜色 --> <color name=</color> <color name="white">#FFFFFF& ...