1

I am getting the following exception

Caused by: java.lang.IllegalArgumentException: Filter mapping specifies an unknown filter name MyFilter
    at org.apache.catalina.core.StandardContext.validateFilterMap(StandardContext.java:3174)
    at org.apache.catalina.core.StandardContext.addFilterMap(StandardContext.java:3139)
    at org.apache.catalina.deploy.WebXml.configureContext(WebXml.java:1343)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1362)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:889)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:386)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5472)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    ... 10 more

The filter is present in a jar file which is part of the delivered war.

@WebFilter(filterName="MyFilter",
        urlPatterns = {"/page/*"})
public class myFilter implements Filter {

Can anybody tell me what i have to do that the filter can be found?

it is not a duplicate of the question java.lang.IllegalArgumentException: The servlets named [X] and [Y] are both mapped to the url-pattern [/url] which is not permitted because it is a very different error message

Jens
  • 67,715
  • 15
  • 98
  • 113
  • @BalusC Yes i have the metadata-complete Attribute. Tomcat Version is Apache Tomcat/7.0.68 – Jens Apr 22 '16 at 11:11
  • Possible duplicate of [java.lang.IllegalArgumentException: The servlets named \[X\] and \[Y\] are both mapped to the url-pattern \[/url\] which is not permitted](https://stackoverflow.com/questions/16270619/java-lang-illegalargumentexception-the-servlets-named-x-and-y-are-both-mapp) – Pankaj Singh Jul 06 '17 at 10:11
  • @Anonymous Why this should be a dupplicate. Everything is different also the error message. BTW. Thanks for downvoting – Jens Jul 06 '17 at 10:36
  • @Downvoter: Thanks for downvoting one ore time without Explanation. It is very helpfull – Jens Aug 30 '17 at 07:36

1 Answers1

4

In other words, the @WebFilter is not recognized. This can happen when you have a metadata-complete="true" attribute in <web-app> element of web.xml. It basically means that the container assumes that the web.xml itself is complete as to metadata and thus it won't scan for metadata (annotations) in JARs shipped in /WEB-INF/lib.

You have several options.

  1. Set metadata-complete="false".
  2. Remove metadata-complete altogether. The default value is already false.
  3. Explicitly register the filter via <filter>.

Another probable cause is a bug in Tomcat which is already fixed in 7.0.28. See also this related question: Using Tomcat, @WebFilter doesn't work with <filter-mapping> inside web.xml.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555