I have a webfilter shared between all my webapps.
@WebFilter(urlPatterns="/*")
public class ApiOriginFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
... do something
}
}
Let's say ApiOriginFilter
belongs to package org.commons.
Now my webapp.ear imports a common library with ApiOriginFilter
.
To make the filter work properly, I had to include it into web.xml, because it seems that if filter belongs to another library it's not enabled by default.
<filter>
<filter-name>ApiOriginFilter</filter-name>
<filter-class>org.commons.filter.ApiOriginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ApiOriginFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Is there any way to make it work without declaring in web.xml ?