How can I use Guice to inject fields into Jersey @BeanParam parameters? <p>This a bit of a weird setup. We've got a web service built on Dropwizard and using Guice for dependency injection. What I want to accomplish is injection of a Guice configured database access object (DAO) into a Jersey REST endpoint <code>@BeanParam</code>.</p> <p>The code (which I drew upon <a href="http://stackoverflow.com/a/18464901/1146608">this answer</a>, <a href="http://stackoverflow.com/q/20600849/1146608">this question</a> and the <a href="https://hk2.java.net/custom-resolver-example.html" rel="nofollow">Jersey HK2 examples</a> looks like this:</p> <p>Authorization annotation interface, <code>Authenticaiton.java</code> </p> <pre><code>@Retention(RetentionPolicy.RUNTIME) @Target({ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD}) public @interface Authentication { } </code></pre> <p>Resolver with nested binder: <code>AuthenticationResolver.java</code></p> <pre><code>@Singleton public class AuthenticatorResolver implements InjectionResolver&lt;Authentication&gt; { protected Authenticator injectableAuthenticator; @Override public Object resolve(Injectee injectee, ServiceHandle&lt;?&gt; root) { return injectableAuthenticator; } @Override public boolean isConstructorParameterIndicator() { return true; } @Override public boolean isMethodParameterIndicator() { return true; } public final class Binder extends AbstractBinder { public Binder(Authenticator authenticator) { injectableAuthenticator = authenticator; } @Override protected void configure() { // @P13NAuthentication bind(AuthenticatorResolver.class).to(new TypeLiteral&lt;InjectionResolver&lt;P13NAuthentication&gt;&gt;() {}).in(Singleton.class); } } } </code></pre> <p>All examples I've found of implementing a <code>Binder</code> for an <code>InjectionResolver</code> show the <code>Binder</code> as a separate class or as a <code>static</code> inner class. I've changed it to a non-static nested class to attempt to simply provide an instance to return via the Binder to the Resolver.</p> <p>The Dropwizard Application class (which is a little deviant from a normal Jersey application because it's essentially a extension wrapper): <code>Service.java</code> </p> <pre><code> AuthenticatorResolver resolver = new AuthenticatorResolver(); AuthenticatorResolver.Binder binder = resolver.new Binder(injector.getInstance(Authenticator.class)); environment.jersey().getResourceConfig().register(binder); </code></pre> <p>At this point, the <code>injector</code> is an instantiated <code>com.google.inject.Injector</code> object with the needed instance of the <code>Authenticator</code> on it. I can see it get added to the instance of the <code>Binder</code>.</p> <p>The class used as the <code>@BeanParam</code> looks like this:</p> <pre><code>public class UserIdentifierContainer implements Serializable { @Authentication Authenticator authenticator; // Bunches of other parameter fields, parsing and validation // Trying to add some magic to verify some fields against the database </code></pre> <p>And I try to add it to an endpoint like so:</p> <pre><code>@PUT @Path("/like/{postId}") public Response putCategoryLike( @BeanParam UserIdentifierContainer userIdentifierContainer, @PathParam("postId") @ApiParam(required=true, value=CATEGORY_ID_DESC) Integer postId, ) throws Exception { </code></pre> <p>Inside of this method I would like the bean to have already validated all the parameters' format and checked the user against the database. However, inside the <code>UserIdentifierContainer</code> object, the <code>Authenticator</code> is null. No error is found trying to resolve an instance of it.</p> <p>I think what's happening is the way the Binder instance gets treated in the application <code>Register()</code> method doesn't preserve the actual instance, or a new AuthenticationResolver has to be constructed somewhere along the way that doesn't get the <code>Authenticator</code> instance needed to return. In other words, my nested class dirty hack didn't work.</p> <p>Is there some other way to get an instantiated object into a resolver for a dead-simple resolve implementation?</p> <p>If not, it seems like I need to make the <code>ServiceHandle</code> object that gets passed into the <code>AuthenticationResolver</code>.<code>resolve()</code> method somehow aware of of <code>Authenticator</code> instance that's been configured by Guice. How can I do this?</p> <p>Or is the best solution to somehow convert the Juice injector to play nicely with the HK2 Service Location paradigm?</p>