在servlet2.4以及之前版本,web容器不支持Listener这种方式,因此只能以Filter的方式配置spring。
在2.5之后版本,按照以下的方式配置:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <!-- 指定版本为web 3.0规范 --> <!-- Spring配置 --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 指定Spring Bean的配置文件所在目录。默认配置在WEB-INF目录下,多个以逗号隔开 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/applicationContext.xml,
</context-param><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list></web-app>WEB-INF/bean.xml</param-value>