title: @WebServlet annotation doesn't work with Tomcat 8
body: <p>I want to use the <code>@WebServlet</code> annotation in a Java EE webapp which runs on Tomcat 8. </p>
  
  <p>I have read that I need to declare Servlet Version 3.1 in my <code>web.xml</code> and that my Servlet needs to extend <code>HttpServlet</code>. I did all that but still the <code>@WebServlet</code> doesn't work. I am getting a HTTP 404. </p>
  
  <p>I also tried my configuration with <code>metadata-complete="false"</code> in my <code>web.xml</code>, but still no success.</p>
  
  <p>Here is my web.xml and Servlet. </p>
  
  <p>The complete sample code can be found <a href="https://github.com/bennyn/heroku-test" rel="noreferrer">on GitHub</a>.</p>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app 
    version="3.1" 
    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_3_1.xsd"&gt;
  
    &lt;context-param&gt;
      &lt;param-name&gt;facelets.DEVELOPMENT&lt;/param-name&gt;
      &lt;param-value&gt;true&lt;/param-value&gt;
    &lt;/context-param&gt;
  
    &lt;!-- http://stackoverflow.com/a/7924117/451634 --&gt;
    &lt;!-- Put "-1" to disable this feature --&gt;
    &lt;context-param&gt;
      &lt;param-name&gt;facelets.REFRESH_PERIOD&lt;/param-name&gt;
      &lt;param-value&gt;1&lt;/param-value&gt;
    &lt;/context-param&gt;
  
    &lt;servlet&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
  
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.xhtml&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
  
    &lt;!-- JSF --&gt;
    &lt;listener&gt;
      &lt;listener-class&gt;org.apache.myfaces.webapp.StartupServletContextListener&lt;/listener-class&gt;
    &lt;/listener&gt;   
  
    &lt;!-- CDI --&gt;
    &lt;listener&gt;
      &lt;listener-class&gt;org.apache.webbeans.servlet.WebBeansConfigurationListener&lt;/listener-class&gt;
    &lt;/listener&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>TestServlet.java</strong></p>
  
  <pre><code>import java.io.IOException;
  import javax.servlet.ServletException;
  import javax.servlet.ServletOutputStream;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  @WebServlet(name = "TestServlet", urlPatterns = {"*.serve"})
  public class TestServlet extends HttpServlet {
  
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
      try (ServletOutputStream out = resp.getOutputStream()) {
        out.write("Hello World".getBytes());
        out.flush();
      }
    }
  
  }
  </code></pre>