title: Tomcat server will not start up with a filter
body: <p>Here is the web.xml code:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://java.sun.com/xml/ns/javaee"   
  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
  &lt;display-name&gt;Projeto_joas&lt;/display-name&gt;
  
  &lt;resource-ref&gt;
  &lt;res-ref-name&gt;jdbc/DiaDiaDev&lt;/res-ref-name&gt;
  &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
  &lt;res-auth&gt;Container&lt;/res-auth&gt;
  &lt;/resource-ref&gt;
  
  
  &lt;servlet&gt;
  &lt;display-name&gt;FacesServlet&lt;/display-name&gt;
  &lt;servlet-name&gt;FacesServlet&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;FacesServlet&lt;/servlet-name&gt;
  &lt;url-pattern&gt;*.jsf&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;context-param&gt;
  &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
  &lt;param-value&gt;Development&lt;/param-value&gt;
   &lt;/context-param&gt;
  
  
  &lt;context-param&gt;
    &lt;param-name&gt;com.sun.faces.expressionFactory&lt;/param-name&gt;
       &lt;param-value&gt;com.sun.el.ExpressionFactoryImpl&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  
  &lt;!-- &lt;filter&gt; --&gt;
  
  &lt;!--&lt;filter-name&gt;FilterHibernate&lt;/filter-name&gt; --&gt;
  &lt;!--&lt;filter-class&gt;util.filter.ConexaoHibernateFilter&lt;/filter-class&gt; --&gt;
  &lt;!--&lt;/filter&gt; --&gt;
  
  &lt;!--&lt;filter-mapping&gt; --&gt;
  &lt;!-- &lt;filter-name&gt;FilterHibernate&lt;/filter-name&gt; --&gt;
  &lt;!--&lt;url-pattern&gt;*.jsf&lt;/url-pattern&gt; --&gt;
  
  &lt;!--&lt;/filter-mapping&gt; --&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>The server runs just fine this way, if i remove the comments on the filter, it won't
  start and will throw me those exceptions:</p>
  
  <blockquote>
    <p>SEVERE: A child container failed during start
    java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
    Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]] 
    Caused by: org.apache.catalina.LifecycleException: A child container failed during start</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>WARNING: Failed to retrieve JNDI naming context for container [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Projeto_joas]] so no cleanup was performed for that container
    javax.naming.NamingException: No naming context bound to this class loader</p>
  </blockquote>
  
  <p>the Filter class:</p>
  
  <pre><code>package util.filter;
  
  import java.io.IOException;
  
  import javax.servlet.Filter;
  import javax.servlet.FilterChain;
  import javax.servlet.FilterConfig;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  
  import org.hibernate.SessionFactory;
  
  import util.HibernateUtil;
  
  public class ConexaoHibernateFilter implements Filter {
  
      private SessionFactory sf;
  
      @Override
      public void init(FilterConfig arg0) throws ServletException {
          this.sf = HibernateUtil.getSessionFactory();
  
      }
  
  
  
  
      @Override
      public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
              FilterChain chain) throws IOException, ServletException {
  
          try {
  
              this.sf.getCurrentSession().beginTransaction();
              chain.doFilter(servletRequest, servletResponse);
              this.sf.getCurrentSession().getTransaction().commit();
              this.sf.getCurrentSession().close();
  
          } catch (Throwable ex) {
              try {
                  if (this.sf.getCurrentSession().getTransaction().isActive()) {
                      this.sf.getCurrentSession().getTransaction().rollback();
                  }
              } catch (Throwable t) {
                  t.printStackTrace();
              }
              throw new ServletException(ex);
          }
  
      }
  
      @Override
      public void destroy() {
          // TODO Auto-generated method stub
  
      }
  
  }
  </code></pre>