title: Could not find a suitable constructor in com.sun.jersey.guice.spi.container.servlet.GuiceContainer
body: <p>I am new to Guice.
  I want to create a server application with RESTful web services and Guice for DI. I followed the tutorial <a href="http://randomizedsort.blogspot.de/2011/05/using-guice-ified-jersey-in-embedded.html" rel="nofollow">here</a>, instead of a jetty I use a Tomcat6. But I cannot get it to run :(</p>
  
  <p>I always get <strong>Could not find a suitable constructor in com.sun.jersey.guice.spi.container.servlet.GuiceContainer</strong> on the application startup.</p>
  
  <p><strong>Exception sending context initialized event to listener instance of class de.server.MyGuiceServletConfig
  com.google.inject.CreationException: Guice creation errors:
  1) Could not find a suitable constructor in com.sun.jersey.guice.spi.container.servlet.GuiceContainer. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
    at com.sun.jersey.guice.spi.container.servlet.GuiceContainer.class(GuiceContainer.java:108)
    at com.sun.jersey.guice.JerseyServletModule.webApp(JerseyServletModule.java:90)</strong></p>
  
  <p>The GuiceContainer class has an constructor with an @Inject statement where it wants an Injector.</p>
  
  <pre><code>  @Inject
  public GuiceContainer(Injector injector) {
      this.injector = injector;
  }
  </code></pre>
  
  <p>My web.xml looks like this:</p>
  
  <pre><code>&lt;web-app id="WebApp_ID" version="2.4"
  xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
  http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
  &lt;display-name&gt;Restful Web Application&lt;/display-name&gt;
  &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;de.server.MyGuiceServletConfig&lt;/listener-class&gt;
  &lt;/listener&gt;
  
  &lt;context-param&gt;
      &lt;param-name&gt;resteasy.scan&lt;/param-name&gt;
      &lt;param-value&gt;true&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;context-param&gt;
      &lt;param-name&gt;resteasy.servlet.mapping.prefix&lt;/param-name&gt;
      &lt;param-value&gt;/rest&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;listener&gt;
      &lt;listener-class&gt;
          org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
      &lt;/listener-class&gt;
  &lt;/listener&gt;
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;resteasy-servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;
          org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
      &lt;/servlet-class&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;resteasy-servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt; 
  </code></pre>
  
  <p></p>
  
  <p>My config class looks like this:</p>
  
  <pre><code>public class MyGuiceServletConfig extends GuiceServletContextListener {
  
  public MyGuiceServletConfig() {
  
  }
  
  public class MyJerseyServletModule extends JerseyServletModule {
      @Override
      protected void configureServlets() {
          // Must configure at least one JAX-RS resource or the
          // server will fail to start.
          bind(ITest.class).to(Test2.class);  
          bind(TestRestService.class);
  
          serve("/*").with(GuiceContainer.class);
      }
  }
  
  @Override
  protected Injector getInjector() {
      return Guice.createInjector(new MyJerseyServletModule());
  }}
  </code></pre>
  
  <p>And last but not least the rest service:</p>
  
  <pre><code>@Path("/test")
  public class TestRestService {
  
  private ITest test;
  
  @Inject
  public TestRestService(ITest t){
      this.test = t;
  }
  
  @GET
  @Path("/getMe")
  public String getMe() {
      return test.getName();
  }
  
  
  @GET
  @Path("/getAll")
  public Response getAll() {
      return Response.status(200).entity("sadsads").build();
  }}
  </code></pre>
  
  <p>I don't know what I am missing. Hope you can tell me what I did wrong...</p>
  
  <p>If you need any further information, just leave a comment and I'll add it.</p>
  
  <p>Thx in advance,
  TJ</p>