Spring @WebFilter与<;过滤器>;在web.xml中
我想知道如何使用@WebFilter注释实现这样的行为Spring @WebFilter与<;过滤器>;在web.xml中,spring,spring-mvc,annotations,servlet-filters,Spring,Spring Mvc,Annotations,Servlet Filters,我想知道如何使用@WebFilter注释实现这样的行为 @WebFilter( urlPatterns = "/*", filterName = "AuthenticationFilter", description = "Filter all URLs" , initParams = { @WebInitParam(name = "unprotectedUrls", value = "/,/login,/authentication,/notificat
@WebFilter(
urlPatterns = "/*",
filterName = "AuthenticationFilter",
description = "Filter all URLs"
,
initParams = {
@WebInitParam(name = "unprotectedUrls", value = "/,/login,/authentication,/notification,/sdr")})
public class AuthenticationFilter implements Filter {
...}
(这很好,这意味着我不必只为列出的路径登录,而是为所有其他必须登录的路径登录)。。。
通过使用web.xml中的元素
在web.xml中使用此筛选器:
<filter>
<filter-name>AuthenticationFilter</filter-name>
<filter-class>com.foo.bar.helper.AuthenticationFilter</filter-class>
<init-param>
<param-name>unprotectedUrls</param-name>
<param-value>/,/login,/authentication,/notification,/sdr</param-value>
</init-param>
</filter>
身份验证过滤器
com.foo.bar.helper.AuthenticationFilter
无保护的
/,/login,/authentication,/notification,/sdr
它无法识别,这意味着我不必登录所有路径/URL。不进行过滤
我的目的是使init参数可配置,以便在需要包含其他URL时不必编辑代码/类。您只定义了过滤器,而没有映射过滤器。在
过滤器
元素旁边,您还需要一个过滤器映射
元素来将过滤器映射到URL,这基本上是@WebFilter
的urlPatterns
属性的替代品
<filter-mapping>
<filter-name> AuthenticationFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
身份验证过滤器
/*
:))是的,的确如此。我同时发现了这一点,但我没有足够的声誉在提问后10小时内回答我自己的问题。但是,谢谢。那么,使用下面的注释@WebFilter(“/*”),我们可以完全不使用web.xml标记吗?