Web开发中Listener、Filter、Servlet的初始化及调用

我们在使用Spring+SpringMVC开发项目中,web.xml中一般的配置如下:

 

Web开发中Listener、Filter、Servlet的初始化及调用

Web开发中Listener、Filter、Servlet的初始化及调用

1 <?xml version="1.0" encoding="UTF-8"?> 2 <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 " version="3.0"> 3 <!-- 加载spring配置 4 默认查找的配置文件位置是:WEB-INF/applicationContext.xml。 5 可通过下面参数指定文件位置--> 6 <context-param> 7 <param-name>contextConfigLocation</param-name> 8 <param-value> 9 classpath:applicationContext.xml 10 </param-value> 11 </context-param> 12 13 <filter> 14 <filter-name>CorsFilter</filter-name> 15 <filter-class>com.filter.CORSFilter</filter-class> 16 </filter> 17 <filter-mapping> 18 <filter-name>CorsFilter</filter-name> 19 <url-pattern>/*</url-pattern> 20 </filter-mapping> 21 22 <listener> 23 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 24 </listener> 25 26 <servlet> 27 <servlet-name>spring-mvc</servlet-name> 28 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 29 <!-- spring mvc 默认加载的配置文件为/WEB-INF/[servlet-name]-servlet.xml,也可通过以下参数指定 --> 30 <!-- <init-param> 31 <param-name>contextConfigLocation</param-name> 32 <param-value>/WEB-INF/spring-mvc-servlet.xml</param-value> 33 </init-param> --> 34 <!-- load-on-startup设置为1,表示项目启动时加载 --> 35 <load-on-startup>1</load-on-startup> 36 </servlet> 37 </web-app>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpjdzp.html