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

免责声明:
    本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除。
    原文作者:zb0567
    原文地址:http://blog.csdn.net/zb0567/article/details/7930642

【转载】Spring中的applicationContext.xml与SpringMVC的xxx-servlet.xml的区别的更多相关文章

  1. Spring中Bean的命名问题及ref和idref之间的区别

    一直在用Spring,其实对其了解甚少,刚去了解了一下Spring中Bean的命名问题以及ref和idref之间的区别,略作记录,以备后查. Spring中Bean的命名 1.每个Bean可以有一个i ...

  2. Spring中利用applicationContext.xml文件实例化对象和调用方法

    Spring中实例化对象和调用方法入门 1.jar包和xml的准备 已上传至百度云盘,链接: https://pan.baidu.com/s/1CY0xQq3GLK06iX7tVLnp3Q 提取码: ...

  3. spring中获取applicationContext

    常用的5种获取spring 中bean的方式总结: 方法一:在初始化时保存ApplicationContext对象代码:ApplicationContext ac = new FileSystemXm ...

  4. 【Spring】Spring中的Bean - 5、Bean的装配方式(XML、注解(Annotation)、自动装配)

    Bean的装配方式 简单记录-Java EE企业级应用开发教程(Spring+Spring MVC+MyBatis)-Spring中的Bean 文章目录 Bean的装配方式 基于XML的装配 基于注解 ...

  5. Spring中,applicationContext.xml 配置文件在web.xml中的配置详解

    一.首先写一下代码结构. 二.再看web.xml中的配置情况. <?xml version="1.0" encoding="UTF-8"?> < ...

  6. Spring中配置文件applicationContext.xml配置详解

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

  7. Spring中的applicationContext.xml实现自动装配

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  8. Spring中的applicationContext文件详解

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  9. Spring中的ApplicationContext事件机制

    ApplicationContext的事件机制是观察者设计模式的实现,通过ApplicationEvent类和ApplicationListerner接口来实现. 1. 创建EmailEvent pu ...

随机推荐

  1. log4net自定义字段写入SqlServer数据库 ASP.net

    首先申明,本示例经过本作者亲自试验通过,可以运行 第一步 编写log4net配置文件 此处为Log.xml,该文件放在与Web.config平级的位置 <?xml version="1 ...

  2. ASP.Net 类(CS)文件怎样获取Web应用程序的路径

    Web应用程序,写了一个线程CS类别,这个类别将会放于Global.asax文件中执行,主要是监控程序下某一个文件是否有异动,而作出相应警示动作,如发送邮件等. 实现运行过程中,也许会有一个情况出现, ...

  3. 实例:使用纹理对象创建Sprite对象

    精灵类是Sprite,它的类图如下图所示: Sprite类直接继承了Node类,具有Node基本特征.此外,我们还可以看到Sprite类的派生类有:PhysicsSprite和Skin.Physics ...

  4. javascript笔记——label包含的自定义按钮选中

    自定义按钮ui样式就是需要有label包含input以及带另外的标签作为新ui的载体,此时触发label的click的时候也会选中按钮,也就是说存在事件捕获,解决这个问题有如下方式 用到了 mouse ...

  5. Ant打jar包指定MainClass

    一般用ant打jar的时候不用指定程序的入口!这个jar一般是给其他app引用的. 但是如果该jar就是程序的启动jar.例如: java -jar abc.jar  这个时候需要指定jar的入口类! ...

  6. 利用word2vec对关键词进行聚类

    1.收集预料 自己写个爬虫去收集网页上的数据. 使用别人提供好的数据http://www.sogou.com/labs/dl/ca.html 2.对预料进行去噪和分词 我们需要content其中的值, ...

  7. 使用DriverManager获取数据库连接

    DriverManager 是驱动的管理类 * 1).可以通过重载的getConnection() 方法获取数据库连接,较为方便 * 2).可以同时管理多个驱动程序,若注册了多个数据库连接,则调用ge ...

  8. 【原】WinForm中的DataGridView加入Combbox或者DropDownButton后,操作变慢

    DataGridView里加入了DropDownButto列,加载数据后点击这一列,反应很慢;要点击三到四次才会展示下拉列表; 原因是DataGridView的EditMode设置问题; 将DataG ...

  9. AngularJS(11)-API

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. Mongodb学习教程汇总

    1.MongoDB权威指南 - 学习笔记 地址:http://www.cnblogs.com/refactor/category/394801.html 2.8天学通MongoDB 地址:http:/ ...