The difference between applicationContext.xml in Spring and xxx-servlet.xml in SpringMVC
一直搞不明白两者的区别。
如果使用了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了。
Second
Spring lets you define mult 大专栏 The difference between applicationContext.xml in Spring and xxx-servlet.xml in SpringMVCiple 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.
More info: Source link
The difference between applicationContext.xml in Spring and xxx-servlet.xml in SpringMVC的更多相关文章
- Spring如何解析XML文件——Spring源码之XML初解析
首先,在我的这篇博客中已经说到容器是怎么初步实现的,并且要使用XmlBeanDefinitionReader对象对Xml文件进行解析,那么Xml文件是如何进行解析的,将在这片博客中进行一些陈述. 数据 ...
- shh整合后web.xml、spring配置文件和struts.xml的内容
1:web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version=" ...
- Difference between applicationContext.xml and spring-servlet.xml in Spring Framework
Question: Are applicationContext.xml and spring-servlet.xml related anyhow in Spring Framework? Will ...
- spring mvc 和spring security配置 web.xml设置
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmln ...
- Spring中加载xml配置文件的六种方式
Spring中加载xml配置文件的六种方式 博客分类: Spring&EJB XMLSpringWebBeanBlog 因为目前正在从事一个项目,项目中一个需求就是所有的功能都是插件的形式装 ...
- Spring MVC的web.xml配置详解(转)
出处http://blog.csdn.net/u010796790 1.spring 框架解决字符串编码问题:过滤器 CharacterEncodingFilter(filter-name) 2.在w ...
- web.xml关于spring的讲解
<context-param>的作用: web.xml的配置中<context-param>配置作用 . 启动一个WEB项目的时候,容器(如:Tomcat)会去读它的配置文件w ...
- Spring mvc的web.xml配置详解
1.spring 框架解决字符串编码问题:过滤器 CharacterEncodingFilter(filter-name) 2.在web.xml配置监听器ContextLoaderListener(l ...
- Spring介绍及配置(XML文件配置和注解配置)
本节内容: Spring介绍 Spring搭建 Spring概念 Spring配置讲解 使用注解配置Spring 一.Spring介绍 1. 什么是Spring Spring是一个开源框架,Sprin ...
随机推荐
- JavaScript学习笔记 - 进阶篇(3)- 流程控制语句
if语句 if语句是基于条件成立才执行相应代码时使用的语句. 语法: if(条件) { 条件成立时执行代码} 注意:if小写,大写字母(IF)会出错! 假设你应聘web前端技术开发岗位,如果你会HTM ...
- POJ 3080 Blue Jeans (求最长公共字符串)
POJ 3080 Blue Jeans (求最长公共字符串) Description The Genographic Project is a research partnership between ...
- day53-线程池
#1.from concurrent import futures可以开启进程池和线程池.concurrent是包,futures是模块,ThreadPoolExecutor是类,submit是方法. ...
- iOS雪花动画、音频图、新闻界面框架、2048游戏、二维码条形码扫码生成等源码
iOS精选源码 粒子雪花与烟花的动画 iOS 2048游戏 JHSoundWaveView - 简单地声波图.音波图 一个可快速集成的新闻详情界面框架,类似今日头条,腾讯新闻 二维码/条形码扫描及扫描 ...
- 基于soap 的 python web services 服务开发指南
文章大纲 序言 相关概念 SOA web services SOAP WSDL UDDI 环境搭建 我们使用 python 3.6 这个较新python 版本 服务端开发 客户端开发 suds-jur ...
- rest framework-视图和路由-长期维护
############### 三种视图 ############### # 第一种方法:使用mixins # class AuthorView(mixins.ListModelMixin, ...
- dedecms_5.7 download.php SQL注入
最近在看Web渗透与漏洞挖掘,这本书的编写目的感觉非常的不错,把渗透和代码审计结合在一起,但是代码审计部分感觉思路个人认为并不是很清晰,在学习dedecms v5.7 SQL注入的时候就只看懂了漏洞, ...
- POJ 3617 Best Cow Line 字典序最小
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #inc ...
- 关于使用MyEclipse自动生成Hibernate和Struts出现的jar不兼容的问题(antlr.collections.AST.getLine()I)
今天做Hibernate和Struts2结合的练习,使用MyEclipse自动创建Hibernate和Struts的相关配置文件和jar包,写完一个查询方法后,准备测试一下结果,简单的查询那种,很诡异 ...
- ValidationUtil
package me.zhengjie.common.utils; import me.zhengjie.common.exception.BadRequestException; import ja ...