`
rochoc
  • 浏览: 10532 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

Spring中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不久,所以暂时理解如此,记下来备忘了


2011-8-25更新,在后面的使用中又发现了新问题,如果用上面的方式,在jsp中是没有办法得到WebApplicationContext的,必须加上ContextLoaderListener后,即需要applicationContext.xml这个配置文件,才能在jsp中用org.springframework.web.context.WebApplicationContext ctx = org.springframework.web.context.support.WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());的方式获取到ApplicationContext,否则获取的就是null。

所以我现在把Controller、View相关的信息放到了xxx-servlet.xml中,把Model、Service之类的信息放到了applicationContext.xml中。
0
3
分享到:
评论
2 楼 rochoc 2011-08-22  

cn-done 写道
contextConfigLocation  指定XML配置文件就可以了
跟文件的名称具体没关系

谢谢
1 楼 cn-done 2011-08-19  
contextConfigLocation  指定XML配置文件就可以了
跟文件的名称具体没关系

相关推荐

    struts.xml和applicationContext.xml、web.xml的配置

    struts.xml和applicationContext.xml、web.xml的配置

    applicationContext-security.xml

    用于配置acegi的xml文件,把这个文件加入项目中,然后建立里面的数据库,引入jar包就可以实现权限的管理

    spring-boot-reference.pdf

    15.2. Importing XML Configuration 16. Auto-configuration 16.1. Gradually Replacing Auto-configuration 16.2. Disabling Specific Auto-configuration Classes 17. Spring Beans and Dependency Injection 18. ...

    shiro-ehcache.xml

    在maven项目中,此shiro-ehcache.xml配置文件放在resources下,在applicationContext.xml中,用于shiro缓存管理器所配置,然后给shiro安全管理器配置此缓存管理器

    spring MVC配置详解

    &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;!-- 可以自定义 servlet.xml 配置文件的位置和名称,默认为 WEB-INF 目录下,名称为[&lt;servlet-name&gt;]-servlet.xml,如 ...

    applicationContext-spring-security-cas.mxl

    PentahoEE版 CAS配置文件,配置完成后实现SSO

    applicationContext.xml 详细配置

    ApplicationContext.xml 文件是 Spring 框架中的核心配置文件,用于定义应用程序的各个组件和依赖关系。通过正确地配置该文件,可以实现应用程序的自动装配和依赖注入,从而提高应用程序的可维护性和可扩展性。

    applicationContext-jedis.xml

    Jedis是Redis官方推荐的Java连接开发工具。Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API...

    applicationContext-trans.xml

    spring事务与传播行为,通知,数据源,切面,,,,,,,

    applicationContext.xml

    Spring applicationContext.xml常见部分属性的使用备注

    struts2-spring-plugin-2.5.13.jar

    搭建struts2 + spring框架时需要使用的关联jar struts.xml中action的属性class引用applicationContext中bean的属性id指向的值

    applicationContext.xml等文件.rar

    包含applicationContext.xml、db.properties、log4j.properties、spring-mvc.xml文件,方便搭建,省去写代码。。

    applicationContext-dao.xml

    #资源达人分享计划# spring配置文件信息 可直接复制稍微修改 主要结合博文进行学习

    Spring 2.5-applicationContext.xml提示信息的配置

    NULL 博文链接:https://mutourenoo.iteye.com/blog/1156865

    applicationContext-dao.xml配置

    NULL 博文链接:https://hs295160903.iteye.com/blog/2314235

    达内汇通项目整合框架SSM

    达内汇通项目整合框架SSM/ht1088/src/main/resources/spring/applicationContext-mybatis.xml /ht1088/src/main/resources/spring/applicationContext-transaction.xml /ht1088/src/main/resources/spring/...

    spring-test.jar

    spring-test.jar 用在junit4以上 在类上写 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"WIN-INF/config/applicationContext.xml" })

    spring+jpa的applicationContext.xml配置

    spring+jpa的applicationContext.xml配置

    spring3.0 + Quartz1.52 + applicationContext.xml

    spring定时任务必须的包和spring配置说明

    spring-test-4.1.2.RELEASE-sources.jar

    因为所有的Bean都需要在applicationContext.xml中加载好,之后再通过@Resource去取得。如果每次都要整个业务流做的差不多了再去测试,这样效率很低,也很麻烦。如果单独去写一个测试用类,这样太繁琐了。于是想起...

Global site tag (gtag.js) - Google Analytics