Spring lets you define multiple contexts in a parent-child hierarchy.

The applicationContext.xml defines the beans for the "root webapp context", i.e. the context associated with the webapp.

The spring-servlet.xml (or whatever else you call it) defines the beans for one servlet's app context. There can be many of these in a webapp, one per Spring servlet (e.g. spring1-servlet.xml for servlet spring1, spring2-servlet.xml for servlet spring2).

Beans in spring-servlet.xml can reference beans in applicationContext.xml, but not vice versa.

All Spring MVC controllers must go in the spring-servlet.xml context.

In most simple cases, the applicationContext.xml context is unnecessary. It is generally used to contain beans that are shared between all servlets in a webapp. If you only have one servlet, then there's not really much point, unless you have a specific use for it.

意思是 在spring mvc中 一个servlet 会对应一个webapplicationContext(ps:也就是 有可能 多个 spring容器)。 而配置applicationContext.xml 只会有一个spring 容器(ps:2中容器是父子容器 是共享的。子容器能访问富容器内容)。 当配置了多个servlet后 就会有多个spring容器 这时候如果在springmvc中配置datasoure 之类的 全局共享的bean 就不合适。。于是 需要 将这种全局共享的 定义到 applicationContext.xml 。

这时候会引发一个问题 父子容器导致 事务失败。如连接:http://blog.csdn.net/liujan511536/article/details/48002885

but 大部分情况我觉得一个servlet足矣

xxx-servlet.xml vs applicationContext.xml的更多相关文章

  1. springmvc.xml和applicationContext.xml配置的特点

    1:springmvc.xml配置要点 一般它主要配置Controller的组件扫描器和视图解析器 下为:springmvc.xml文件 <?xml version="1.0" ...

  2. 浅谈配置文件:spring-servlet.xml(spring-mvc.xml) 与 applicationContext.xml

    在搭建 spring mvc 的框架时,会有2个配置文件必不可少: spring-servlet.xml 和applicationContext.xml.第一次接触spring mvc的工程师可能会对 ...

  3. 在web.xml注册applicationContext.xml配置文件

    概要: Spring配置文件是集成了Spring框架的项目的核心,引擎的开始是:容器先是加载web.xml,接着是applicationContext.xml在web.xml里的注册.以下我们将介绍a ...

  4. spring-mvc.xml 和 application-context.xml的区别

    转自:https://www.cnblogs.com/binlin1987/p/7053016.html application-context.xml是全局的,应用于多个serverlet,配合li ...

  5. spring-mvc.xml 和 application-context.xml的配置与深入理解

    在java框架这个话题,前几篇文章是基于搭建ssm项目框架,以及web.xml的配置讲解,本篇主要就ssm框架的其他配置文件进行深入讲解,他们分别是:1.application-context.xml ...

  6. web.xml配置错误导致applicationContext.xml配置重复加载

    web.xml相关配置 <context-param><param-name>log4jRefreshInterval</param-name><param- ...

  7. @Value取不到值引出的spring的2种配置文件applicationContext.xml和xxx-servlet.xml

    项目中经常会用到配置文件,定义成properties的形式比较常见,为了方便使用一般在spring配置文件中做如下配置: <context:property-placeholder ignore ...

  8. 【转载】Spring中的applicationContext.xml与SpringMVC的xxx-servlet.xml的区别

    一直搞不明白两者的区别. 如果使用了SpringMVC,事实上,bean的配置完全可以在xxx-servlet.xml中进行配置.为什么需要applicationContext.xml?一定必须? 一 ...

  9. SpringMVC 常用applicationContext.xml、web.xml、servlet-mvc.xml简单配置

    在进行学习配置文件之前,为了加深对框架的认识,简单的做了SSM框架的简单实验.然后画出listAll查询方法的整个过程的思维导图. 整个过程中的web.xml.SpringMVC.xml.applic ...

随机推荐

  1. Spring Bean基本管理--bean注入方式汇总

    依赖注入方式:Spring支持两种依赖注入方式,分别是属性注入和构造函数注入.还有工厂方法注入方式. 依赖注入还分为:注入依赖对象可以采用手工装配或自动装配,在实际应用开发中建议使用手工装配,因为自动 ...

  2. Dev gridControl 按回车增加一行

    将NewItemRowPosition属性设置为Top或Bottom, 在这样的新行中输入数据后,会自动添加到绑定的数据源中的, 如果你希望在按回车时焦点跳至下一列, 只需要设置GridView的Op ...

  3. UILabel 自适应大小

    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStylealloc]init]; paragraphStyle.lineB ...

  4. <转>准备Eclips+python+robot framework环境

    关于python: path添加:C:\Python27;C:\Python27\Scripts; 新加一项:  PYTHON_HOME    C:\Python27 再不行的话,加一个用户变量: P ...

  5. 双nginx(主备、主主)反向代理tomcat实现web端负载均衡

    经过以前做完的产品,受前公司几位前辈技术大拿指点,来自己动手实现并总结一下web端的负载解决方法,高手请略过,个人认知有限,请各位指正错误. 下面是结构图: 我的系统环境是Fedora22(适用rea ...

  6. LeetCode题解——Unique Path(DP与优化)

    题目:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). ...

  7. 关于FireFox下 CSS3 transition 与其他浏览器的差异

    最近一个项目,动画效果全靠CSS3来做,用得比较多的transition,发现了一点火狐与其他浏览器的小差异. 首先我们写CSS的时候,一般为属性值为0的属性,我们一般会这样写 #id{ posito ...

  8. kendoui-grid篇

    kendo确实是个好东西,能够让我们专注于后端开发,无需在效果呈现上花大力气,唯一的缺点,它是收费的,但是我目前还没发现为嘛要掏钱,因为free的也满足了我的需求. kendoUI For asp.m ...

  9. Tkinter教程之Pack篇

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1813077 '''Tkinter教程之Pack篇'''#Pack为一布局管理器,可将它视为一个 ...

  10. 【转】VC6.0附带小工具软件一览

    )ActiveX Control Test Container称为"ActiveX 控件测试容器",顾名思义,此工具的主要功能就是测试ActiveX 控件,可以通过改变Active ...