title: Dropwizard - Can't register a jersey resource using Guice Injector.getIntance()
body: <p>I have used this setup successfully in previous methods with supervision so I'm probably doing something wrong now. I am mainly using Guice for its AOP part. </p>
  
  <p>Relevant sections of pom.xml:</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;io.dropwizard&lt;/groupId&gt;
          &lt;artifactId&gt;dropwizard-core&lt;/artifactId&gt;
          &lt;version&gt;0.7.0&lt;/version&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.jboss.logging&lt;/groupId&gt;
                  &lt;artifactId&gt;jboss-logging&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.google.inject&lt;/groupId&gt;
          &lt;artifactId&gt;guice&lt;/artifactId&gt;
          &lt;version&gt;4.0&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;aopalliance&lt;/groupId&gt;
          &lt;artifactId&gt;aopalliance&lt;/artifactId&gt;
          &lt;version&gt;1.0&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
          &lt;artifactId&gt;lombok&lt;/artifactId&gt;
          &lt;version&gt;1.16.6&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>BaseBindingModule:</p>
  
  <pre><code>public class BaseBindingModule extends AbstractModule{
  
      @Override
      protected void configure() {
          bindInterceptor(any(), annotatedWith(SendCrashReport.class), new CrashReport());    
          bind(CabManager.class).to(CabManagerImpl.class);
      }
  }
  </code></pre>
  
  <p>The file where resources are registered:</p>
  
  <pre><code>public class BucService extends Application&lt;BucConfiguration&gt; {
      public static void main(String[] args) throws Exception {
          new BucService().run(args);
      }
  
      @Override
      public void initialize(Bootstrap&lt;BucConfiguration&gt; bootstrap) {
          //bootstrap.setName("hello-world");
      }
  
      @Override
      public void run(BucConfiguration configuration,
                      Environment environment) {
          final String template = configuration.getTemplate();
          final String defaultName = configuration.getDefaultName();
          environment.jersey().register(new HelloWorldResource(template, defaultName));
  
          Injector injector = Guice.createInjector(new BaseBindingModule ());
          environment.jersey().register(injector.getInstance(CabResource.class)); // this does not work
        //  environment.jersey().register(new CabResource()); // this works
      }
  }
  </code></pre>
  
  <p>The actual resource file:</p>
  
  <pre><code>@Path("/cabs")
  @Produces(MediaType.APPLICATION_JSON)
  public class CabResource {
  
      @Inject
      CabManager manager;
  
  
      public CabResource() {
      }
  
      @GET
      @Path("price")
      @Produces(MediaType.APPLICATION_JSON)
      public List&lt;PriceEstimate&gt; getCheapestCabs() {
  
          return manager.callB();
      }
  
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      @SendCrashReport
      public List&lt;PriceEstimate&gt; getNearestCabs(@Context UriInfo uriInfo) {
  
          return manager.callA();
        }
  
  }
  </code></pre>
  
  <p>When I try to register the resource using Guice Injector.getInstance(), it doesn't get registered and I can't access any of the REST API's.</p>
  
  <p>However if I simply register the resource as new CabResource(), the API's are visible. But in that case I wont be able to make GUICE AOP to work as per this answer:
  <a href="https://stackoverflow.com/a/8862599/1443801">https://stackoverflow.com/a/8862599/1443801</a></p>
  
  <p>What am I missing?</p>
  
  <p>Thanks.</p>
  
  <p>Edit: This is what shows when I run the jar file. Note that there are no cab API's.</p>
  
  <pre><code>INFO  [2016-04-01 13:26:14,785] io.dropwizard.server.ServerFactory: Starting BucService
  INFO  [2016-04-01 13:26:14,876] org.eclipse.jetty.setuid.SetUIDListener: Opened application@758a34ce{HTTP/1.1}{0.0.0.0:9000}
  INFO  [2016-04-01 13:26:14,876] org.eclipse.jetty.setuid.SetUIDListener: Opened admin@7ec3394b{HTTP/1.1}{0.0.0.0:9001}
  INFO  [2016-04-01 13:26:14,877] org.eclipse.jetty.server.Server: jetty-9.0.z-SNAPSHOT
  INFO  [2016-04-01 13:26:14,965] com.sun.jersey.server.impl.application.WebApplicationImpl: Initiating Jersey application, version 'Jersey: 1.18.1 02/19/2014 03:28 AM'
  INFO  [2016-04-01 13:26:15,060] io.dropwizard.jersey.DropwizardResourceConfig: The following paths were found for the configured resources:
  
      GET     /hello-world (com.buc.resources.HelloWorldResource)
  
  INFO  [2016-04-01 13:26:15,262] org.eclipse.jetty.server.handler.ContextHandler: Started i.d.j.MutableServletContextHandler@6c451c9c{/,null,AVAILABLE}
  INFO  [2016-04-01 13:26:15,263] io.dropwizard.setup.AdminEnvironment: tasks = 
  
      POST    /tasks/gc (io.dropwizard.servlets.tasks.GarbageCollectionTask)
  
  WARN  [2016-04-01 13:26:15,264] io.dropwizard.setup.AdminEnvironment: 
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  !    THIS APPLICATION HAS NO HEALTHCHECKS. THIS MEANS YOU WILL NEVER KNOW      !
  !     IF IT DIES IN PRODUCTION, WHICH MEANS YOU WILL NEVER KNOW IF YOU'RE      !
  !    LETTING YOUR USERS DOWN. YOU SHOULD ADD A HEALTHCHECK FOR EACH OF YOUR    !
  !         APPLICATION'S DEPENDENCIES WHICH FULLY (BUT LIGHTLY) TESTS IT.       !
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  INFO  [2016-04-01 13:26:15,269] org.eclipse.jetty.server.handler.ContextHandler: Started i.d.j.MutableServletContextHandler@3dddbe65{/,null,AVAILABLE}
  INFO  [2016-04-01 13:26:15,279] org.eclipse.jetty.server.ServerConnector: Started application@758a34ce{HTTP/1.1}{0.0.0.0:9000}
  INFO  [2016-04-01 13:26:15,280] org.eclipse.jetty.server.ServerConnector: Started admin@7ec3394b{HTTP/1.1}{0.0.0.0:9001}
  </code></pre>
  
  <p>Further clarification based on the comments:</p>
  
  <p>I do get an instance using injector.getInstance(CabResource.class).</p>
  
  <p>For example:</p>
  
  <pre><code>CabResource a = new CabResource();
  CabResource b = injector.getInstance(CabResource.class);
  
  a.getCheapestCabs(); 
  b.getCheapestCabs();
  </code></pre>
  
  <p>both of the calls work.</p>