Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Clone this wiki locally
Yahhh – PostConstruct me now unt PreDestroy me lay-tuh
What is Governator?
Governator is a library of extensions and utilities that enhance Google Guice to provide:
- Classpath scanning and automatic binding
- Lifecycle management
- Injector bootstrapping
- Configuration to field mapping
- Field validation
- Parallelized object warmup
- Lazy singleton
- Fine grained, more concurrent singleton
- Generic binding annotations
Classpath scanning and automatic binding
Governator introduces the annotations
@AutoBind. See the Auto Binding wiki for details.
Governator adds support for the standard annotations:
@Resource. See the Lifecycle Management wiki for details.
Governator simplifies bootstrapping the Guice injector by providing a single Builder on which various operations can be applied to determine the final set of modules used to create the injector. These include, adding modules, overriding modules (coming soon), module transitive dependencies, suites of configuration sets, module transformations, post injector creation hooks, etc. In addition Governator provides an annotation based approach to further simply bootstrapping an application via a single main configuration class.
Configuration to field mapping
Governator introduces a new annotation
@Configuration that can be used to annotate class fields. Governator will assign the fields using configuration from property files, etc. Another annotation is also introduced,
@PreConfiguration, for methods to be called prior to configuration assignment. See the Configuration Mapping wiki for details.
Governator supports the
javax.validation annotations (JSR 303). Fields annotated with validation annotations will get validated via the Hibernate Validator. See the Field Validation wiki for details.
Parallelized object warmup
Governator introduces the new annotation
@WarmUp. Methods annotated with
@WarmUp will get executed (in parallel) after injected by Guice. See the Warm Up wiki for details.
Governator adds a LazySingleton annotation and scope. This is the opposite of Guice’s Eager Singletons. Lazy singletons are not created until just before they are to be injected regardless of Guice’s Stage. See the Lazy Singleton wiki for details.
Fine Grained, More Concurrent Singletons
Guice’s default Singleton scope synchronizes all object creation on a single lock (InternalInjectorCreator.class). It does this to avoid deadlocks with circular dependencies. FineGrainedLazySingleton instead locks on the key so that multiple singletons can be created concurrently. See the Concurrent Singleton wiki for details.
Generic Binding Annotations
com.netflix.governator.annotations.binding package contains a set of generic binding annotations that you might find useful. These might be more clear and more maintainable to users than using Guice’s
@Named. The full set can be found here: binding-annotations
Module transitive dependencies
The Governator bootstrap phase makes it easy to pull in Guice modules and their transitive dependencies without having to worry about duplicate bindings.
Simplified integration with various application containers by adding a single Guice module. Support is provided for standalone applications.
It’s assumed that you are familiar with Google Guice.
Maven / Artifacts
Governator binaries are published to Maven Central.