xxx-servlet.xml vs applicationContext.xml
2015-08-29 16:09
417 查看
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足矣
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足矣
相关文章推荐
- ios中创建可以拖动的view原理和实现详解(含代码)
- Android下raw文件夹下获取不到多媒体文件的缩略图
- 浅谈iOS内存管理机制
- 3分钟制作一个APP,六款国际热门互联网产品
- 初识 swift 封装轮播图
- Appium的python_client的安装过程解析。
- ios开发-OC-封装、继承、多态
- Android应用插件式开发解决方法
- Android 热更新——非侵入AOP框架
- iOS唯一表示符获取方案
- Unity Application 前后台切换调用关系
- android的广播事件
- yii2 加手机端信息
- Android应用程序用户界面(五)
- iOS开发--Kiwi使用进阶 Mock, Stub, 参数捕获和异步测试
- ios引入zxing二维码识别子工程遇到的问题
- 最新的全网速下载Android Sdk更新与下载
- android service与activity进行通信
- 虚幻4 UObject被删除
- Android中消息系统模型和Handler Looper