web.xml
<!--
指定spring的配置文件,默认从web根目录寻找配置文件,我们可以通过spring提供的classpath:前缀指定从类路径下寻找
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-security.xml,/WEB-INF/application-common.xml</param-value>
</context-param>
<!-- log4j Listener -->
<listener>
<listener-class>net.mickey.listener.ProductLog4jListener</listener-class>
</listener>
<!-- 对Spring容器进行实例化 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 这个监听器会在session 创建和销毁的时候通知Spring Security -->
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<!-- 加载spring Security 过滤器 -->
<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>
<!--
指定spring的配置文件,默认从web根目录寻找配置文件,我们可以通过spring提供的classpath:前缀指定从类路径下寻找
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-security.xml,/WEB-INF/application-common.xml</param-value>
</context-param>
<!-- log4j Listener -->
<listener>
<listener-class>net.mickey.listener.ProductLog4jListener</listener-class>
</listener>
<!-- 对Spring容器进行实例化 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 这个监听器会在session 创建和销毁的时候通知Spring Security -->
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<!-- 加载spring Security 过滤器 -->
<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>
本文介绍如何在web.xml中配置Spring Security过滤器及监听器,并设置自定义的Log4j监听器来管理日志记录。具体包括指定Spring配置文件的位置、启用ContextLoaderListener以初始化Spring上下文、配置HttpSessionEventPublisher以处理会话事件,以及通过DelegatingFilterProxy加载Spring Security过滤器。

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



