title: Using Tomcat, @WebFilter doesn't work with <filter-mapping> inside web.xml
body: <p>Here's a working web.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
  
      &lt;session-config&gt;
          &lt;session-timeout&gt;30&lt;/session-timeout&gt;
      &lt;/session-config&gt;
  
       &lt;filter&gt;
          &lt;filter-name&gt;rememberMeCookieFilter&lt;/filter-name&gt;
          &lt;filter-class&gt;be.example.fun.jsp.filters.RememberMeCookieFilter&lt;/filter-class&gt;
      &lt;/filter&gt;
  
      &lt;filter&gt;
          &lt;filter-name&gt;mustBeSignedInFilter&lt;/filter-name&gt;
          &lt;filter-class&gt;be.example.fun.jsp.filters.MustBeSignedInFilter&lt;/filter-class&gt;
      &lt;/filter&gt;
  
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;rememberMeCookieFilter&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;mustBeSignedInFilter&lt;/filter-name&gt;
          &lt;url-pattern&gt;/private/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>When I remove the <code>&lt;filter&gt;</code> elements and use the following annotations instead:</p>
  
  <pre><code>@WebFilter(filterName="rememberMeCookieFilter")
  public class RememberMeCookieFilter implements Filter
  
  @WebFilter(filterName="mustBeSignedInFilter")
  public class MustBeSignedInFilter implements Filter
  </code></pre>
  
  <p>Then Tomcat 7.0.14 gives me the following error:</p>
  
  <pre class="lang-none prettyprint-override"><code>java.lang.IllegalArgumentException: Filter mapping must specify either a &lt;url-pattern&gt; or a &lt;servlet-name&gt;
      at org.apache.catalina.core.StandardContext.validateFilterMap(StandardContext.java:2956)
      at org.apache.catalina.core.StandardContext.addFilterMap(StandardContext.java:2915)
      at org.apache.catalina.deploy.WebXml.configureContext(WebXml.java:1180)
      at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1270)
          ...
  </code></pre>
  
  <p>I followed the answer of <a href="https://stackoverflow.com/questions/6560969/how-to-define-servlet-filter-order-of-execution-using-annotations">this question</a>, but that doesn't work for me.</p>
  
  <p>Here are the dependencies of my web application:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;dependencies&gt;
          &lt;!-- SLF4J (+ LOGBack) for logging --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
              &lt;version&gt;1.6.4&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
              &lt;artifactId&gt;logback-core&lt;/artifactId&gt;
              &lt;version&gt;1.0.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
              &lt;artifactId&gt;logback-classic&lt;/artifactId&gt;
              &lt;version&gt;1.0.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.codehaus.groovy&lt;/groupId&gt;
              &lt;artifactId&gt;groovy&lt;/artifactId&gt;
              &lt;version&gt;1.8.3&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- The servlet API that I installed in my local repo --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
              &lt;version&gt;3.0&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
              &lt;!--optional&gt;false&lt;/optional--&gt;
          &lt;/dependency&gt;
  
          &lt;!-- JUnit for testing --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.8.2&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  </code></pre>
  
  <p>EDIT: I only have the issue when using Tomcat (7.0.14). Glassfish is fine.</p>