edit

Governator integration

Include the Netflix Governator dependency:

compile "com.netflix.governator:governator:1.5.11"

Governator owns injector creation, so we need to create custom guicey InjectorFactory

public class GovernatorInjectorFactory implements InjectorFactory {
    public Injector createInjector(final Stage stage, final Iterable<? extends Module> modules) {
        return LifecycleInjector.builder().withModules(modules).inStage(stage).build().createInjector();
    }
}

Configure new factory in guice bundle:

@Override
public void initialize(Bootstrap<Configuration> bootstrap) {
    bootstrap.addBundle(GuiceBundle.builder()
            .injectorFactory(new GovernatorInjectorFactory())
            .enableAutoConfig("com.mycompany.myapp")
            ...
            .build()
    );
}

Note

Auto scan is enabled and managed bean, described below, will be discovered and installed automatically (assuming its inside scanned package).

Governator Lifecycle

Many Governator enhancements are only available when the Governator LifecycleManager is properly started and closed with the application.

Use dropwizard's managed object to control governator lifecycle:

import io.dropwizard.lifecycle.Managed;
import ru.vyarus.dropwizard.guice.GuiceBundle;
import com.netflix.governator.lifecycle.LifecycleManager;
import javax.inject.Inject;

public class GovernatorLifecycle implements Managed {

    @Inject
    private LifecycleManager manager;

    @Override
    public void start() throws Exception {
        manager.start();
    }

    @Override
    public void stop() throws Exception {
        manager.close();
    }
}

Guicey will find this managed bean, create governator injector (using custom factory), create managed bean instance and register it in dropwizard. This will "bind" governator lifecycle to dropwizard lifecycle.

Note

If you need to run this managed before or after some other dropwizard managed use guicey @Order annotation.