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 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配置文件和spring mvc配置文件的区别的更多相关文章

  1. Spring MVC配置文件的三个常用配置详解

    转自:http://www.cnblogs.com/benwu/articles/5162614.html Spring MVC项目中通常会有二个配置文件,sprng-servlet.xml和appl ...

  2. spring+hibernate+jpa+Druid的配置文件,spring整合Druid

    spring+hibernate+jpa+Druid的配置文件 spring+hibernate+jpa+Druid的完整配置 spring+hibernate+jpa+Druid的数据源配置 spr ...

  3. spring mvc context-param init-param 区别

    init-param:mvc 配置文件context-param spring配置文件

  4. spring boot与spring mvc的区别

    Spring 框架就像一个家族,有众多衍生产品例如 boot.security.jpa等等.但他们的基础都是Spring 的 ioc和 aop ioc 提供了依赖注入的容器 aop ,解决了面向横切面 ...

  5. 2017.2.13 开涛shiro教程-第十二章-与Spring集成(一)配置文件详解

    原博客地址:http://jinnianshilongnian.iteye.com/blog/2018398 根据下载的pdf学习. 第十二章-与Spring集成(一)配置文件详解 1.pom.xml ...

  6. Spring中两种引入配置文件方式

    用过Spring的人都知道,我们一般把数据库的配置.日志的配置或者其他的通用配置放在单独的配置文件中,在和Spring整合时,一般通过以下两种方法引入: <context:property-pl ...

  7. Spring Boot 核心注解与配置文件

    @SpringBootApplication注解 Spring Boot项目有一个入口类 (*Application) 在这个类中有一个main 方法,是运行该项目的切入点.而@SpringBootA ...

  8. Spring Boot 与 Spring MVC到底有什么区别

    前言 Spring 框架就像一个家族,有众多衍生产品例如 boot.security.jpa等等.但他们的基础都是Spring 的 ioc和 aop ioc 提供了依赖注入的容器 aop ,解决了面向 ...

  9. spring加载多个配置文件

    首先我们都知道要使用spring,则需要在web.xml中增加如下代码: web.xml: 1:<listener><listener-class>org.springfram ...

  10. Spring中加载xml配置文件的六种方式

    Spring中加载xml配置文件的六种方式 博客分类: Spring&EJB XMLSpringWebBeanBlog  因为目前正在从事一个项目,项目中一个需求就是所有的功能都是插件的形式装 ...

随机推荐

  1. Spring Boot教程(七)通过springboot 去创建和提交一个表单

    创建工程 涉及了 web,加上spring-boot-starter-web和spring-boot-starter-thymeleaf的起步依赖. <dependencies> < ...

  2. tar中的参数 cvf,xvf,cvzf,zxvf的区别

    tar cvf etcbak.tar etc/  打包一个tar tar xvf etcbak.tar         解开一个tar tar cvzf etcbak.tar.gz etc/ 打包压缩 ...

  3. 重读APUE(6)-umask

    umask函数设置当前进程的权限为屏蔽字:系统会有一个默认的屏蔽字,为了确保创建文件具有的权限位成功被设置,需要使用umask将屏蔽字置0: 系统屏蔽字用shell查看,比如得到如下结果,其为八进制表 ...

  4. iOS-VideoToolbox硬编码H264

    前言 VideoToolBox是iOS8之后,苹果开发的用于硬解码编码H264/H265(iOS11以后支持)的API. 对于H264还不了解的童鞋一定要先看下这边的H264的简介. 编码流程 我们实 ...

  5. java课后实验性问题7

    1.异常处理 import javax.swing.*; class AboutException { public static void main(String[] a) { int i = 1, ...

  6. Redis监控之redis-stat安装与详解

    一.安装环境 安装编译环境.ruby运行环境.git代码 yum install gcc-c++ yum -y install ruby-devel yum install ruby yum inst ...

  7. Flume-自定义 Source

    Source 是负责接收数据到 Flume Agent 的组件. Source 组件可以处理各种类型.各种格式的日志数据,包括 avro.thrift.exec.jms.spooling direct ...

  8. webpack 用 webpack-parallel-uglify-plugin 加速打包报错

    从新拉了份代码.npm install .npm run dev 都没有问题,但是npm run build 就报上面的错误了 查了好多资料,都没有解决上面的问题,也不知道是哪里出了问题,但是可以肯定 ...

  9. 图解 HTTP 笔记(六)——HTTP 首部

    本章主要讲解了 HTTP 首部的结构,已经首部中各字段的用法. 一.HTTP 报文首部 上图是 HTTP 请求报文的结构. HTTP 请求报文由方法.URI.HTTP 版本.HTTP 首部字段等组成. ...

  10. 类型TTreeView.items.add 与 TTreeView.items.addchild有何区别?(10分)

    我看了书上例子,好象两者都可以实现treeview中的node 的构建. addchild是给当前的node建一个子node,它比当前node要向右缩进几格add建立同级的node,不缩进 aNode ...