Governator integration

Include the Netflix Governator dependency:

implementation ""

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())


Guicey by default parses configured guice modules and so injector factory receives single synthetic module of parsed elements, instead of configured module instances. Some governator features may require exact module instances and so you may need to disable guicey analysis.

Also, when using overriding modules configuration (with #modulesOverride configuration) injector factory also receives syntetic module after {@code Modules.override(modules).with(overridingModules)}. So you will have not to use this feature when direct module instances required (for some governator features).


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.