Based on Arithraโs own answer:
Honestly, I don't know for sure if this works with Guice 3.0, but it works for 4.0, which is the current stable version.
I think a slightly cleaner approach is to change my CustomConfigurator to something like this:
public class CustomConfigurator extends Configurator { @Inject private static Injector injector; public <T> T getEndpointInstance(Class<T> endpointClass) { return injector.getInstance(endpointClass); } }
And then from the extended ServletModule class' configureServlets method call requestStaticInjection(CustomConfigurator.class)
Thus, you will not expose the injector to everyone. I donโt know about you, but it gives me a pleasant and fuzzy feeling inside, to know that no one can bother with their injector :-).
source share