【发布时间】:2020-10-11 00:49:27
【问题描述】:
应用程序服务器无法启动 servlet 过滤器。
错误消息是java.lang.NoSuchMethodException: package.MyCustomFilter.<init>()。
HttpFilter 扩展了实现 init() 方法的 GenericFilter。所以没有必要覆盖它。我已经尝试过重写 init() 方法它没有解决问题。
过滤器类:
public class MyCustomFilter extends HttpFilter {
private static final long serialVersionUID = -5281928035553598730L;
private static Logger log = Logger.getLogger(MyCustomFilter.class.getName());
protected MyCustomFilter() {
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
super.doFilter(req, res, chain);
log.info("filter Request");
}
}
web.xml
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0">
...
<filter>
<filter-name>myCustomFilter</filter-name>
<filter-class>com.dtmarius.gateway.filter.MyCustomFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>myCustomFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
【问题讨论】:
标签: java tomcat servlet-filters apache-tomee