title: Passing servlet config parameters under Servlet spec 3.0
body: <p>When using annotations instead of a web.xml file, what do you do with the servlet init/config parameters that you can normally read from the <a href="http://tomcat.apache.org/tomcat-7.0-doc/servletapi/javax/servlet/ServletConfig.html" rel="nofollow">ServletConfig</a> object? ie </p>
  
  <pre><code>@WebFilter("/sample")
  public class MyServlet {
  
      public void init() throws ServletException {
          String value = getServletConfig().getInitParameter("key");
          // or
          value = getServletContext().getInitParameter("key");
      }
  }
  </code></pre>
  
  <p>or in the case of a filter:</p>
  
  <pre><code>public class MyFilter implements Filter {
  
      public void init (FilterConfig filterConfig) throws ServletException {
          filterConfig.getInitParameter("key");
      }
  
  }
  </code></pre>
  
  <p><strong>UPDATE:</strong> I know you can hardcode configuration parameters in an annotation, but I dont want to hardcode configuration settings into the code. For example, this servlet could not be shared between two applications:</p>
  
  <pre><code>@WebFilter("/sample", initParams = {@InitParam(name = "database_host", value = "blah.com")})
  public class MyServlet {
  
      public void init() throws ServletException {
          String value = getServletConfig().getInitParameter("database_host");
      }
  }
  </code></pre>