因为直接使用了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中。
分享到:
相关推荐
struts.xml和applicationContext.xml、web.xml的配置
用于配置acegi的xml文件,把这个文件加入项目中,然后建立里面的数据库,引入jar包就可以实现权限的管理
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. ...
在maven项目中,此shiro-ehcache.xml配置文件放在resources下,在applicationContext.xml中,用于shiro缓存管理器所配置,然后给shiro安全管理器配置此缓存管理器
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 可以自定义 servlet.xml 配置文件的位置和名称,默认为 WEB-INF 目录下,名称为[<servlet-name>]-servlet.xml,如 ...
PentahoEE版 CAS配置文件,配置完成后实现SSO
ApplicationContext.xml 文件是 Spring 框架中的核心配置文件,用于定义应用程序的各个组件和依赖关系。通过正确地配置该文件,可以实现应用程序的自动装配和依赖注入,从而提高应用程序的可维护性和可扩展性。
Jedis是Redis官方推荐的Java连接开发工具。Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API...
spring事务与传播行为,通知,数据源,切面,,,,,,,
Spring applicationContext.xml常见部分属性的使用备注
搭建struts2 + spring框架时需要使用的关联jar struts.xml中action的属性class引用applicationContext中bean的属性id指向的值
包含applicationContext.xml、db.properties、log4j.properties、spring-mvc.xml文件,方便搭建,省去写代码。。
#资源达人分享计划# spring配置文件信息 可直接复制稍微修改 主要结合博文进行学习
NULL 博文链接:https://mutourenoo.iteye.com/blog/1156865
NULL 博文链接:https://hs295160903.iteye.com/blog/2314235
达内汇通项目整合框架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 用在junit4以上 在类上写 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"WIN-INF/config/applicationContext.xml" })
spring+jpa的applicationContext.xml配置
spring定时任务必须的包和spring配置说明
因为所有的Bean都需要在applicationContext.xml中加载好,之后再通过@Resource去取得。如果每次都要整个业务流做的差不多了再去测试,这样效率很低,也很麻烦。如果单独去写一个测试用类,这样太繁琐了。于是想起...