在 WEB 环境下使用 Spring
1) 需要额外加入的 jar 包:
spring-web-4.0.0.RELEASE.jar
2) Spring 的配置文件和非 WEB 环境没有什么不同
3) 需要在 web.xml 文件中加入如下配置:
<!-- 配置 Spring 配置文件的名称和位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- 启动 IOC 容器的 ServletContextListener -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
本文介绍了如何在Web环境中配置Spring框架,包括所需添加的jar包、配置文件的位置及加载方式,以及通过ServletContextListener启动IOC容器的具体步骤。

被折叠的 条评论
为什么被折叠?



