Question:

  • Are applicationContext.xml and spring-servlet.xml related anyhow in Spring Framework?
  • Will the properties files declared in applicationContext.xml be available to DispatcherServlet?
  • On a related note, why do I need a *-servlet.xml at all? Why is applicationContext.xmlalone insufficient?

Answer:

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.xmlfor servlet spring1spring2-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.

Difference between applicationContext.xml and spring-servlet.xml in Spring Framework的更多相关文章

  1. Spring MVC 零配置 / Spring MVC JavaConfig

    1. Spring MVC的核心就是DispatcherServlet类,Spring MVC处理请求的流程如下图所示: 2. Spring MVC中典型的上下文层次 当我们初始化一个Dispatch ...

  2. The difference between applicationContext.xml in Spring and xxx-servlet.xml in SpringMVC

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

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

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

  4. Spring MVC web.xml+servlet.xml

    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" " ...

  5. spring web.xml 难点配置总结

    web.xml web.xml是所有web项目的根源,没有它,任何web项目都启动不了,所以有必要了解相关的配置. ContextLoderListener,ContextLoaderServlet, ...

  6. Spring 通过XML配置文件以及通过注解形式来AOP 来实现前置,环绕,异常通知,返回后通知,后通知

    本节主要内容: 一.Spring 通过XML配置文件形式来AOP 来实现前置,环绕,异常通知     1. Spring AOP  前置通知 XML配置使用案例     2. Spring AOP   ...

  7. spring web.xml 难点配置总结【转】

    web.xml web.xml是所有web项目的根源,没有它,任何web项目都启动不了,所以有必要了解相关的配置. ContextLoderListener,ContextLoaderServlet, ...

  8. Caused by: java.io.FileNotFoundException: class path resource [spring/springmvc.xml] cannot be opene

                        Caused by: java.io.FileNotFoundException: class path resource [spring/springmvc. ...

  9. 使用web.xml方式加载Spring时,获取Spring context的两种方式

    使用web.xml方式加载Spring时,获取Spring context的两种方式: 1.servlet方式加载时: [web.xml] <servlet> <servlet-na ...

随机推荐

  1. vue.js学习笔记之v-bind,v-on

    v-bind 指令用于响应地更新 HTML 特性 形式如:v-bind:href    缩写为    :href; v-on 指令用于监听DOM事件 形式如:v-on:click  缩写为 @clic ...

  2. JS判断数组中是否有重复元素的方法

    判断数组中是否有重复元素,最容易想到的方法是使用2重循环,逐个遍历,比较,但是这个是最慢,最笨的方法,百度得出了更好的方法. var ary = new Array("111",& ...

  3. C#高级进阶--重写函数

    这里要说一下,重写是继承时发生,在子类中重新定义父类中的方法.例如:基类方法声明为virtual方法,派生类中使用override声明此方法的重写. 基类中的访问修饰符在子类中是不能被修改的.比如说基 ...

  4. ASP.NET复合控件

    ① DropDownList 下拉列表 会被编译为select option ps.name 服务端常用,id 客户端常用 一般用法: 一.将数据放进去 方法一:同WinForm相同,给定数据源,然后 ...

  5. 媒体查询判断ipad与iPhone各版本i

    /* 判断ipad */ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px){ /* s ...

  6. SqlServer和MySQL游标学习

    一 sqlserver游标使用 /*** 游标的使用  讲了这个多游标的优点,现在我们就亲自来揭开游标的神秘的面纱.  使用游标的顺序: 声名游标.打开游标.读取数据.关闭游标.删除游标. 1.3.1 ...

  7. ubuntu下minicom和USB转串口(转)

    ubuntu下minicom和USB转串口(转)   minicom是linux下串口通信的软件,它的使用完全依靠键盘的操作,虽然没有“超级终端”那么易用,但是使用习惯之后读者将会体会到它的高效与便利 ...

  8. 收藏的牛人的Backbone分享教程

    http://yujianshenbing.iteye.com/category/256978 感谢御剑神兵,目前正在看,为源码分析做准备. 今天是2015年4月13号,看了前两篇,

  9. CodeForces 688C-NP-Hard Problem

    题意: 给你一个无向图,判断是否能够构成一个二分图,如果能的话,输出二分图左边的集合和右边的集合 分析: 先给每一个顶点的color初始化-1,表示没有被染色,用vector数组v[a],表示元素a所 ...

  10. linux命令每日一练习-top free

    top看看进程的内存使用情况 free产看内存使用情况 top -n 2 -b > log.txt   将更新两次的结果输入到log.txt cat > log.txt //清空文件并写入 ...