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.

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事务管理的一些注意点

    在<Spring Boot事务管理(下)>中,已经介绍了如果在 protected.private 或者默认可见性的方法上使用@Transactional,事务将是摆设,也不会抛出任何异常 ...

  2. 求ascii 然后做运算

    介绍 ABC 返回每个字符的ascii A->65 B->66 C->77 组成656667 把所有的7替换成1 然后变成 656667 和 656661 每个数值做加法 然后做减法 ...

  3. linux安装maven简易步骤

    版本要求maven3.6.1 软件下载 wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.6.1/binaries/apache-maven-3 ...

  4. 重读APUE(11)-信号安全的可重入函数

    重入时间点 进程捕捉到信号并对其进行处理时,进程正在执行的正常指令序列就会被信号处理程序临时中断,它首先执行该信号粗合理程序中的指令:如果从信号处理程序返回,则继续执行捕捉到信号时进程正在执行的正常指 ...

  5. AngularJS开发中常用的写法,如:获取URL参数、路由跳转、$http、获取元素等

    控制器,带状态 app.controller('editCtrl', ['$http', '$location', '$rootScope', '$scope', '$state', '$stateP ...

  6. Spring事务知识点

    事务的传播属性 PROPAGATION_REQUIRED 如果当前没有事务,就新建一个事务,如果已经存在一个事务中,加入到这个事务中.// 最常用,@Transactional注解默认 PROPAGA ...

  7. 检测系统中进程占满单个cpu的情况

    #!/bin/bash function thread_used_cpu(){ # $1 为单个cpu负载的百分比 if [[ $1 == "" ]];then full_load ...

  8. insmod mknod

    insmod module 會在 /proc/devices/ 下產生 major number 及 device name ---------------------------- mknod 會使 ...

  9. ClipDrawable

    Clip可以译为剪的意思,我们可以把ClipDrawable理解为从位图上剪下一个部分; Android中的进度条就是使用ClipDrawable来实现的,他根据设置level的值来决定剪切 区域的大 ...

  10. C++ STL partial_sort

    #include <iostream>#include <deque>#include <algorithm>#include <vector> usi ...