一直搞不明白两者的区别。
如果使用了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.
- 浏览: 349256 次
- 性别:
- 来自: 青岛
最新评论
-
贝塔ZQ:
java实现操作word的读取和修改操作,用插件实现的话,可以 ...
java用poi实现对word读取和修改操作 -
yh412:
[flash=200,200][url][img]引用[/im ...
java用poi实现对word读取和修改操作 -
2047699523:
最代码 http://www.zuidaima.com 提供 ...
Java经典代码 -
漫成咖啡:
如何制作卡片型单据 -
geekant:
import com.swing.lx.table 这个包是你 ...
JTable的表头合并
Spring中的applicationContext.xml与SpringMVC的xxx-servlet.xml的区别
- 博客分类:
- Spring
相关推荐
这是一些配置文件,可以作为参考,个人感觉很方便的学习方法
applicationContext.xml 详细配置
Spring applicationContext.xml常见部分属性的使用备注
spring4的“所有jar包”+applicationContext.xml+web.xml====全套
struts.xml和applicationContext.xml、web.xml的配置
ssm框架基础配置文件,不需要自己每次都手动敲,拿来即用,注意修改少数几个路径,超级方便。
包含applicationContext.xml、db.properties、log4j.properties、spring-mvc.xml文件,方便搭建,省去写代码。。
详解Spring的applicationContext.xml文件代码:
spring定时任务必须的包和spring配置说明
applicationContext.xml详解
在SSH的applicationContext.xml 中如何配制配制事务
Spring[applicationContext.xml]灵活性代理
NULL 博文链接:https://mutourenoo.iteye.com/blog/1156865
本篇文章主要介绍了详解spring applicationContext.xml 配置文件 ,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
SSH框架applicationContext.xml头部文件
Spring Boot技术知识点:如何读取不同路径里的applicationContext.xml配置文件4
spring+jpa的applicationContext.xml配置