spring web项目 加入@WebFilter类未生效,研究了下是web.xml头未配置正确
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
过滤类如下
@Service
@WebFilter(filterName = "CommonFilter", urlPatterns = "/*")
public class CommonFilter implements Filter {
private Logger logger = LoggerFactory.getLogger(CommonFilter.class);
public void init(FilterConfig filterConfig) throws ServletException {
logger.info("================= init xxxxx ====================");
// WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
}
/**
* 通用的总过滤器
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(request, response);
}
public void destroy() {
logger.info("======destroy=comment=====");
}
}