Skip to content

Governator integration

Include the Netflix Governator dependency:

compile ""

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 the new factory in the guice bundle:

public void initialize(Bootstrap<Configuration> bootstrap) {
            .injectorFactory(new GovernatorInjectorFactory())


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 javax.inject.Inject;

public class GovernatorLifecycle implements Managed {

    private LifecycleManager manager;

    public void start() throws Exception {

    public void stop() throws Exception {

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


If you need to control the order which the managed beans are started, use the @Order annotation.