xxx-servlet.xml vs applicationContext.xml
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的更多相关文章
- springmvc.xml和applicationContext.xml配置的特点
1:springmvc.xml配置要点 一般它主要配置Controller的组件扫描器和视图解析器 下为:springmvc.xml文件 <?xml version="1.0" ...
- 浅谈配置文件:spring-servlet.xml(spring-mvc.xml) 与 applicationContext.xml
在搭建 spring mvc 的框架时,会有2个配置文件必不可少: spring-servlet.xml 和applicationContext.xml.第一次接触spring mvc的工程师可能会对 ...
- 在web.xml注册applicationContext.xml配置文件
概要: Spring配置文件是集成了Spring框架的项目的核心,引擎的开始是:容器先是加载web.xml,接着是applicationContext.xml在web.xml里的注册.以下我们将介绍a ...
- spring-mvc.xml 和 application-context.xml的区别
转自:https://www.cnblogs.com/binlin1987/p/7053016.html application-context.xml是全局的,应用于多个serverlet,配合li ...
- spring-mvc.xml 和 application-context.xml的配置与深入理解
在java框架这个话题,前几篇文章是基于搭建ssm项目框架,以及web.xml的配置讲解,本篇主要就ssm框架的其他配置文件进行深入讲解,他们分别是:1.application-context.xml ...
- web.xml配置错误导致applicationContext.xml配置重复加载
web.xml相关配置 <context-param><param-name>log4jRefreshInterval</param-name><param- ...
- @Value取不到值引出的spring的2种配置文件applicationContext.xml和xxx-servlet.xml
项目中经常会用到配置文件,定义成properties的形式比较常见,为了方便使用一般在spring配置文件中做如下配置: <context:property-placeholder ignore ...
- 【转载】Spring中的applicationContext.xml与SpringMVC的xxx-servlet.xml的区别
一直搞不明白两者的区别. 如果使用了SpringMVC,事实上,bean的配置完全可以在xxx-servlet.xml中进行配置.为什么需要applicationContext.xml?一定必须? 一 ...
- SpringMVC 常用applicationContext.xml、web.xml、servlet-mvc.xml简单配置
在进行学习配置文件之前,为了加深对框架的认识,简单的做了SSM框架的简单实验.然后画出listAll查询方法的整个过程的思维导图. 整个过程中的web.xml.SpringMVC.xml.applic ...
随机推荐
- css3属性及事例
在看网上别的前端大牛的作品时,总会有新的收获,我想很多人应该都知道box-shadow,但是不知道有没有接触过这个 box-shadow: 2px 2px 4px rgba(0,0,0,0.4) , ...
- 强制将IE8设置为IE7兼容模式来解析网页
强制将IE8设置为IE7兼容模式来解析网页 英文原文:http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx 文件兼容性用于定义让IE ...
- 如何打开和关闭Oracle Flashback
1.打开flashback: 关闭数据库 SQL>shutdown immediate; 启动到mount方式 SQL>startup mount; 如果归档没有打开,打开归档[因为fla ...
- Using Open Source Static Libraries in Xcode 4
Using Open Source Static Libraries in Xcode 4 Xcode 4.0.1 allows us to more easily create and use th ...
- Maximum Product Subarray JAVA实现
题目描述: Find the contiguous subarray within an array (containing at least one number) which has the la ...
- Mondriaan's Dream(POJ 2411状态压缩dp)
题意:用1*2的方格填充m*n的方格不能重叠,问有多少种填充方法 分析:dp[i][j]表示i行状态为j时的方案数,对于j,0表示该列竖放(影响下一行的该列),1表示横放成功(影响下一列)或上一列竖放 ...
- 深入学习Android有关网络连接的内容
基于实际项目中碰到的些许问题,开始重新深入学习Android网络连接有关知识. Android的4.1.2版本的AndroidHttpClient模块setSoTimeout之后实际超时时间和设置的时 ...
- 感知器Perceptron
Perceptron: 1.一种基于监督的线性分类器,其特点是:1)模型简单,具有很少的学习参数:2)具有可视性,一条直线即可划分:3)基于人工神经网络的原理. 其结构图为: 2.学习的关键技术: ...
- sizeof和strlen小结
sizeof和strlen小结 写在前面 之所以要总结一下sizeof和strlen的用法和区别,是因为这些知识可以帮助我们更加深入的理解各种数据结构在内存中的占用情况,也许表面上看好像没有多大用处, ...
- C语言中 v...printf类函数的用法
C语言的自学渐渐接近尾声,今天学到了标准库中的stdarg.h头,里面关联了stdio.h头里面的一类函数:v...printf函数,里面举的例子看了之后还是不太明白,google了一下依旧不是很懂, ...