Spring MVC 指导文档解读(一)
22.1 指导文档章节
In the Web MVC framework, each DispatcherServlet has its own WebApplicationContext, which inherits all the beans already defined in the root WebApplicationContext.
解读
一、 DispatcherServlet 可以定义多个
二、 root WebApplicationContext 适用于所有的 DispatcherServlet ,换句话说是继承所有root中定义的bean。(经过实验,如果在root中定义一个单例bean,则这个bean的实例被所有servlet的上下文所共享,必须使用指定linstener才能加载root的配置文件 )
三、 可以通过 默认配置文件/初始化参数配置文件 定义自己私有的 context ,换句话说定义自己的beans.
备注
① 默认配置文件:
a file named [servlet-name]-servlet.xml in the WEB-INF directory .
② 初始化参数配置文件:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:s22-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
param-value 为 resources ,多种引入方式查看 8. Resources
通常使用 classpath:a/b/c.xml
Line n1: 2016-10-03 21:19:17 INFO XmlBeanDefinitionReader:317 - Loading XML bean definitions from ServletContext resource [/WEB-INF/s1-servlet.xml]
Line n2: 2016-10-03 21:19:18 INFO XmlBeanDefinitionReader:317 - Loading XML bean definitions from class path resource [s22-servlet.xml]
通过日志可以看出,默认形式使用的是servlet 规范,而自己指定 contextConfigLocation 则是 spring 的形式
这两种效果相同,都是为了加载spring bean ,这些bean 是绑定servlet的,在谁的里面声明了,谁就能用,其他servlet不能使用。
还可以说,如果不存在 root context,那么每个servlet 都有自己专属的上下文,自己声明的bean,只能在自己上下文中使用。
如果存在 root context ,那么root context 中定义的bean 被所有servlet 共享,是整个应用的上下文。(参数名同servlet init ,必须使用listener)
<!-- Configuration locations must consist of one or more comma- or space-delimited
fully-qualified @Configuration classes. Fully-qualified packages may also be
specified for component-scanning -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:rootContext-Beans.xml</param-value>
</context-param> <!-- Bootstrap the root application context as usual using ContextLoaderListener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<param-value>classpath:a.xml classpath:b.xml</param-value>
<param-value>classpath:a.xml,classpath:b.xml</param-value>
上面两个正确
<param-value>classpath:a.xml b.xml</param-value>
上面这个是错误的
已验证。
Spring MVC 指导文档解读(一)的更多相关文章
- Spring MVC 指导文档解读(二)
Special Bean Types In the WebApplicationContext 解读 1.WebApplicationContext 特有的几种 Bean Types 2. 也表明 与 ...
- 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= ...
随机推荐
- 高亮代码显示之HTML困惑
近期做样式库,需要将HTML代码高亮,开始寻找相关的插件. 看到highlight.js,看到它主题样式如此之多,支持语言也如此之多,以为找到了神器.不想这只是痛苦的开始,为了让它支持HTML,我尝试 ...
- 移动端UC浏览器和QQ浏览器的部分私有meta属性
UC浏览器 1.设置屏幕横屏还是竖屏 <meta name="screen-orientation" content="portrait | landscape&q ...
- MyEclipse+Tomcat 启动时出现A configuration error occured during startup错误的解决方法
MyEclipse+Tomcat 启动时出现A configuration error occured during startup错误的解决方法 分类: javaweb2013-06-03 14:4 ...
- CSS+HTML网页设计与布局(学习笔记1)
1.在宽度未知时,使div块居中,可以添加以下属性: display:table;margin:0 auto;
- HttpURLConnection下载图片的两种方式
public class MainActivity extends AppCompatActivity { private ImageView iv; private String imageurl ...
- loadrunner工具使用之脚本创建
loadrunner工具使用之脚本创建 一.创建脚本 1.打开loadrunner,选择第一个控件VuGen(创建/编辑脚本),点击
- Oracle 数据整理
/* 大数据这块用到了 Oracle ... 记录一下. */ SELECT ssn,password FROM (Select ROWNUM AS ROWNO, T.* from ACCOUNT T ...
- Hibernate之jpa实体映射的三种继承关系
在JPA中,实体继承关系的映射策略共有三种:单表继承策略(table per class).Joined策略(table per subclass)和Table_PER_Class策略. 1.单表继承 ...
- afterTextChanged() callback being called without the text being actually changed
afterTextChanged() callback being called without the text being actually changed up vote8down votefa ...
- Towers of Hanoi
Your mission is to move the stack from the left peg to the right peg. The rules are well known: Only ...