spring框架的web.xml文件解读

来源:互联网 发布:2017沥青路面设计软件 编辑:程序博客网 时间:2024/06/05 17:41
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">  <listener>       <!--   在web.xml中注册这个listener可以保证在web应用关闭的时候释放掉与这个web应用相关的class loader和由它管理的类.    -->    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>  </listener>  <!--       以防乱码   -->  <filter>    <filter-name>encodingFilter</filter-name>    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>    <init-param>      <param-name>encoding</param-name>      <param-value>UTF-8</param-value>    </init-param>  </filter>  <filter-mapping>    <filter-name>encodingFilter</filter-name>    <url-pattern>*</url-pattern>  </filter-mapping>  <!--   如果spring配置文件被命名为applicationContext.xml,并且放在WEB-INF目录下,则不需要配置<context-param>,  因为ContextLoaderListener默认在WEB-INF目录下寻找名为applicationContext.xml的文件。  若要放于WEB-INF/classes/目录下,或若存在多个Spring配置文件,则需要上面的配置,且在<param-value>中依次列出,之间以逗号隔开。也可以不用逗号   -->  <context-param>    <param-name>contextConfigLocation</param-name>         <param-value>          /WEB-INF/classes/conf/spring/spring-admin.xml,            /WEB-INF/classes/conf/spring/applicationContext-security.xml           </param-value>  </context-param>      <!--   ContextLoaderListener通过读取contextConfigLocation参数来读取配置参数,一般来说它配置的是Spring项目的中间层,服务层组件的注入,装配,AOP.   对应到Spring的自动装配机制<context:component-scan>就是以下几种注解的装配   DAO: such as @Repository bean   Entity: such as @Entity bean   Service: such as @Service bean   ContextLoaderListener,它实现了ServletContextListener监听器接口,   ServletContextListener只负责监听web容器启动和关闭的事件   -->  <listener>    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  </listener>    <!--   而RequestContextListener实现ServletRequestListener监听器接口,该监听器监听HTTP请求事件,web服务器   接收的每一次请求都会通知该监听器。   -->  <listener>    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>  </listener>  <!--   这个监听器实现了HttpSessionListener接口,主要监听sessionCreated、sessionDestroyed事件。  可统计在线人数清除已经失效的session信息以及session对应的认证实体信息,避免造成oom   -->  <listener>    <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>  </listener>      <filter>    <filter-name>springSecurityFilterChain</filter-name>    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>  </filter>  <filter-mapping>    <filter-name>springSecurityFilterChain</filter-name>    <url-pattern>/*</url-pattern>  </filter-mapping>  <filter>    <filter-name>sitemeshFilter</filter-name>    <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>  </filter>  <filter-mapping>    <filter-name>sitemeshFilter</filter-name>    <url-pattern>*.jsp</url-pattern>  </filter-mapping>    <filter-mapping>    <filter-name>sitemeshFilter</filter-name>    <url-pattern>*.htm</url-pattern>  </filter-mapping>  <filter-mapping>    <filter-name>sitemeshFilter</filter-name>    <url-pattern>/*</url-pattern>  </filter-mapping>  <servlet>    <servlet-name>springMVC</servlet-name>    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>    <init-param>      <param-name>contextConfigLocation</param-name>      <param-value>        classpath*:/conf/spring/spring-quartz.xml      </param-value>    </init-param>        <load-on-startup>1</load-on-startup>  </servlet>  <servlet-mapping>    <servlet-name>springMVC</servlet-name>    <url-pattern>*.htm</url-pattern>  </servlet-mapping>  <session-config>    <session-timeout>30</session-timeout>  </session-config>  <error-page>    <error-code>404</error-code>    <location>/pages/exception/pageNotFound.jsp</location>  </error-page>  <error-page>    <error-code>500</error-code>    <location>/pages/exception/pageError.jsp</location>  </error-page>  <!-- <welcome-file-list>    <welcome-file>/auth/login.htm</welcome-file>  </welcome-file-list> -->  <servlet>    <servlet-name>Faces Servlet</servlet-name>    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>    <load-on-startup>1</load-on-startup>  </servlet>  <servlet-mapping>    <servlet-name>Faces Servlet</servlet-name>    <url-pattern>*.faces</url-pattern>  </servlet-mapping></web-app>

原创粉丝点击