applicationContext.xml与xxx-servlet.xml的区别?
2016-03-07 11:51
459 查看
一、 因为直接使用了SpringMVC,所以之前一直不明白xxx-servlet.xml和applicationContext.xml是如何区别的,其实如果直接使用SpringMVC是可以不添加applicationContext.xml文件的。 使用applicationContext.xml文件时是需要在web.xml中添加listener的: <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> 而这个一般是采用非spring mvc架构,如使用struts之类而又想引入spring才添加的,这个是用来加载Application Context。 如果直接采用SpringMVC,只需要把所有相关配置放到xxx-servlet.xml中就OK了。 二、 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.
相关文章推荐
- springmvc-servlet.xml,applicationContext.xml 哪个先被执行?
- spring里头各种获取ApplicationContext的方法
- #android# 广播静态注册 动态注册
- android AsyncTask的参数理解
- 【iOS】加密算法整理
- 两种Android判断view是否部分被遮挡(或者移出屏幕)的方法
- 夺命雷公狗---微信开发49----获取用户列表接口(1)
- 《从零开始学Swift》学习笔记(Day 56)—— Swift编码规范之命名规范
- 参考:xUtils 包含了很多实用的android工具
- ios开发者证书 签发者无效
- Android 原生BottomSheet 介绍及坑
- quick-cocos2d-x 游戏开发——StateMachine 状态机
- Android设置透明、半透明等效果
- android 源码 log
- android自定义控件:根据声音波动的声波控件
- 第一个Android 例子
- Android开发之如何保证Service不被杀掉(broadcast+system/app)
- unity提取打包资源
- iOS开发--开发者帐号
- android如何调用@hide和internal API