HubSpot/dropwizard-guice

Dropwizard 0.8 introduces Jersey 2.x support

Closed this issue · 6 comments

Since DW 0.8 seems to use Jersey 2 (with HK2), will dropwizard-guice be adapted?

We can create a separate version! PR welcome!

Apparently this might not be straightforward, there is an open issue on Jersey related to Guice support

I'd like to see this too! Trying it out with 0.8.0-SNAPSHOT I get this:

Exception in thread "main" java.lang.NoSuchMethodError: io.dropwizard.jersey.setup.JerseyEnvironment.getResourceConfig()Lcom/sun/jersey/api/core/ResourceConfig;
at com.hubspot.dropwizard.guice.GuiceBundle.run(GuiceBundle.java:114)
at com.hubspot.dropwizard.guice.GuiceBundle.run(GuiceBundle.java:24)
at io.dropwizard.setup.Bootstrap.run(Bootstrap.java:176)
at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:41)
at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:76)
at io.dropwizard.cli.Cli.run(Cli.java:70)
at io.dropwizard.Application.run(Application.java:73)
at com.grommitz.dropwiz.App.main(App.java:22)

At work we had some luck to hacking together a Guice enabled Jersey2 war-based application that used various Dropwizard 0.8.0 dependencies. We used the HK2 Guice bridge based on their instructions. So the code look something like this:

@Inject
public class ApiApplication extends ResourceConfig
{
    public ApiApplication( final ServiceLocator serviceLocator )
    {
        GuiceBridge.getGuiceBridge().initializeGuiceBridge( serviceLocator );
        GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService( GuiceIntoHK2Bridge.class );
        guiceBridge.bridgeGuiceInjector( injector );
    }
}

And in the web.xml:

<servlet>
    <servlet-name>ApiApplication</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>com.apmasphere.api.ApiApplication</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

However I haven't been able to figure out how to connect these dots in a standard alone Dropwizard 0.8.0 application. For starters I can't seem to get the ServiceLocator which is needed to create the Guice Bridge. Still investigating.

I think this should be closed now with the merging of #45 and the latest 0.8 release?

Yup, I agree! Closing.