title: Java/Guice Error configuring application listener of class MyExample.GuiceServletConfig
body: <p>I'm trying to get a bare-boned framework going and I'm having some trouble getting it to actually run.</p>
  
  <p>The following files are all in the 'example' package:</p>
  
  <p><em>AbstractController.java</em></p>
  
  <pre><code>package example;
  
  import java.io.IOException;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import com.google.inject.Singleton;
  
  
  @Singleton
  @SuppressWarnings("serial")
  public abstract class AbstractController extends HttpServlet {
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      }
      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          doGet(request, response);
      }
  }
  </code></pre>
  
  <p><em>ApplicationInitializer.java</em></p>
  
  <pre><code>package example;
  
  import com.google.inject.Inject;
  //import com.google.inject.persist.PersistService;
  
  public class ApplicationInitializer {
      @Inject
      ApplicationInitializer() {
          // stuff comes here later
      }
  }
  </code></pre>
  
  <p><em><strong>GuiceServletConfig.java</em></strong></p>
  
  <pre><code>package example;
  
  import com.google.inject.Guice;
  import com.google.inject.Injector;
  import com.google.inject.servlet.GuiceServletContextListener;
  import com.google.inject.servlet.ServletModule;
  
  public class GuiceServletConfig extends GuiceServletContextListener {       
      @Override
      protected Injector getInjector() {
  
          Injector injector = Guice.createInjector(new ServletModule() {
              @Override
              protected void configureServlets() {        
  
                  // direct to servlets
                  serve("/Example").with(ServerController.class);
                  serve("/*").with(ServerController.class);
  
  
              }
          }/*, new ProductionModule()*/);
  
          injector.getInstance(ApplicationInitializer.class);
  
          return injector;
      }
  
  }
  </code></pre>
  
  <p><em>ProductionModule.java</em></p>
  
  <pre><code>package example;
  
  import com.google.inject.AbstractModule;
  
  public class ProductionModule extends AbstractModule {
      @Override
      protected void configure() {
          // stuff comes later
      }
  }
  </code></pre>
  
  <p><em>ServerController.java</em></p>
  
  <pre><code>package example;
  
  import java.io.IOException;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import com.google.inject.Singleton;
  
  @Singleton
  @SuppressWarnings("serial")
  public class ServerController extends AbstractController {
  
      //@Inject
      public ServerController() {
          // future dependencies
      }
  
      @Override
      protected void doGet(HttpServletRequest request,
              HttpServletResponse response) throws ServletException, IOException {
  
          request.getRequestDispatcher("WEB-INF/pages/test.jsp").forward(request, response);
      }
  
  }
  </code></pre>
  
  <p>I've added the following to my web.xml, near the top:</p>
  
  <pre><code>&lt;filter&gt;
      &lt;filter-name&gt;guiceFilter&lt;/filter-name&gt;
      &lt;filter-class&gt;com.google.inject.servlet.GuiceFilter&lt;/filter-class&gt;
    &lt;/filter&gt;
  
    &lt;filter-mapping&gt;
      &lt;filter-name&gt;guiceFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;example.GuiceServletConfig&lt;/listener-class&gt;
      &lt;/listener&gt;
  </code></pre>
  
  <p>But for some reason, I get the following stacktrace: (running on Tomcat, as service)</p>
  
  <pre><code>Aug 06, 2013 3:58:44 PM org.apache.catalina.core.AprLifecycleListener init
  INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.7.0_21\jre\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Java\jre7\bin;C:\Program Files\Java\jre7\bin\.;C:\Program Files\Java\jdk1.7.0_21\bin;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\eclipse;;.
  Aug 06, 2013 3:58:45 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
  WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:CIMPUI' did not find a matching property.
  Aug 06, 2013 3:58:45 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
  WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:MyExample' did not find a matching property.
  Aug 06, 2013 3:58:45 PM org.apache.coyote.AbstractProtocol init
  INFO: Initializing ProtocolHandler ["http-bio-8080"]
  Aug 06, 2013 3:58:45 PM org.apache.coyote.AbstractProtocol init
  INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
  Aug 06, 2013 3:58:45 PM org.apache.catalina.startup.Catalina load
  INFO: Initialization processed in 371 ms
  Aug 06, 2013 3:58:45 PM org.apache.catalina.core.StandardService startInternal
  INFO: Starting service Catalina
  Aug 06, 2013 3:58:45 PM org.apache.catalina.core.StandardEngine startInternal
  INFO: Starting Servlet Engine: Apache Tomcat/7.0.41
  Aug 06, 2013 3:58:45 PM org.apache.catalina.core.StandardContext listenerStart
  SEVERE: Error configuring application listener of class MyExample.GuiceServletConfig
  java.lang.ClassNotFoundException: MyExample.GuiceServletConfig
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
      at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527)
      at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509)
      at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4823)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      at java.util.concurrent.FutureTask.run(FutureTask.java:166)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:722)
  
  Aug 06, 2013 3:58:45 PM org.apache.catalina.core.StandardContext listenerStart
  SEVERE: Skipped installing application listeners due to previous error(s)
  Aug 06, 2013 3:58:45 PM org.apache.catalina.core.StandardContext startInternal
  SEVERE: Error listenerStart
  Aug 06, 2013 3:58:45 PM org.apache.catalina.core.StandardContext startInternal
  SEVERE: Context [] startup failed due to previous errors
  Aug 06, 2013 3:58:45 PM org.apache.catalina.core.StandardContext listenerStart
  SEVERE: Error configuring application listener of class MyExample.GuiceServletConfig
  java.lang.ClassNotFoundException: MyExample.GuiceServletConfig
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
      at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527)
      at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509)
      at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4823)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      at java.util.concurrent.FutureTask.run(FutureTask.java:166)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:722)
  
  Aug 06, 2013 3:58:45 PM org.apache.catalina.core.StandardContext listenerStart
  SEVERE: Skipped installing application listeners due to previous error(s)
  Aug 06, 2013 3:58:45 PM org.apache.catalina.core.StandardContext startInternal
  SEVERE: Error listenerStart
  Aug 06, 2013 3:58:45 PM org.apache.catalina.core.StandardContext startInternal
  SEVERE: Context [/CIMPUI] startup failed due to previous errors
  Aug 06, 2013 3:58:45 PM org.apache.catalina.core.StandardContext listenerStart
  SEVERE: Error configuring application listener of class MyExample.GuiceServletConfig
  java.lang.ClassNotFoundException: MyExample.GuiceServletConfig
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
      at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527)
      at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509)
      at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4823)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
      at java.util.concurrent.FutureTask.run(FutureTask.java:166)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:722)
  
  Aug 06, 2013 3:58:45 PM org.apache.catalina.core.StandardContext listenerStart
  SEVERE: Skipped installing application listeners due to previous error(s)
  Aug 06, 2013 3:58:45 PM org.apache.catalina.core.StandardContext startInternal
  SEVERE: Error listenerStart
  Aug 06, 2013 3:58:45 PM org.apache.catalina.core.StandardContext startInternal
  SEVERE: Context [/MyExample] startup failed due to previous errors
  Aug 06, 2013 3:58:45 PM org.apache.coyote.AbstractProtocol start
  INFO: Starting ProtocolHandler ["http-bio-8080"]
  Aug 06, 2013 3:58:45 PM org.apache.coyote.AbstractProtocol start
  INFO: Starting ProtocolHandler ["ajp-bio-8009"]
  Aug 06, 2013 3:58:45 PM org.apache.catalina.startup.Catalina start
  INFO: Server startup in 557 ms
  </code></pre>
  
  <p>I've been troubleshooting this for a great while now and would love to get it to actually do something other than throw exceptions. Any ideas?</p>