有瑕疵的老兵 2015-07-07
在 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>