Home

Awesome

dropwizard-guicier

A Dropwizard bundle to handle Guice integration.

Usage

    <dependencies>
        <dependency>
            <groupId>com.hubspot.dropwizard</groupId>
            <artifactId>dropwizard-guicier</artifactId>
            <version>1.3.5.2</version>
        </dependency>
    </dependencies>

Simply install a new instance of the bundle during your service initialization

public class ExampleApplication extends Application<ExampleConfiguration> {

  public static void main(String... args) throws Exception {
    new ExampleApplication().run(args);
  }

  @Override
  public void initialize(Bootstrap<ExampleConfiguration> bootstrap) {
    GuiceBundle<ExampleConfiguration> guiceBundle = GuiceBundle.defaultBuilder(ExampleConfiguration.class)
        .modules(new ExampleModule())
        .build();

    bootstrap.addBundle(guiceBundle);
  }

  @Override
  public void run(ExampleConfiguration configuration, Environment environment) throws Exception {}
}

Features

Examples

There is an example project you can clone and play with if you'd like to get going right away.

Upgrading from dropwizard-guice

There are a couple important changes to be aware of when upgrading from dropwizard-guice.

AutoConfig has been removed

Reasoning and potential workarounds are discussed here (fwiw we've ditched AutoConfig internally and have never looked back).

Explicit Bindings Required

By default, dropwizard-guicier installs a module which makes Guice run in a more strict mode. In particular, just-in-time bindings are disabled and all objects must be explicitly bound. In addition, it requires that no-arg constructors are annotated with @Inject for Guice to use them. You can opt out of having this module installed by calling enableGuiceEnforcer(false) when constructing your GuiceBundle.