Configuration hooks

Guicey provides special mechanism for external configuration:

public class MyHook implements GuiceyConfigurationHook {
    public void configure(GuiceBundle.Builder builder) {
        builder.bundles(new AdditinoalBundle());    

Hook implementation receive the same builder instance as used in GuiceBundle and so it is able to change everything (for example, GuiceyBundle abilities are limited).


Hooks intended to be used in tests (e.g. to activate some diagnostic tools or disable application parts) and to activate diagnostic/tracking tools on compiled application.


When hook implemented as separate class it could be registered directly:

new MyHook().register()

For lambda-hook registration use:

ConfigurationHooksSupport.register(builder -> { 
    // do modifications 


All hooks are executed just before guice bundle builder finalization (when you call last .build() method of GuiceBundle). Hooks registered after this moment will simply be never used.



For hooks usage in tests there is a special test support (spock and junit).

In context of tests, the most important hook modifications are:

  • Change options
  • Disable any bundle, installer, extension, module
  • Register disable predicate (to disable features by package, registration source etc.)
  • Override guice bindings
  • Register additional bundles, extensions, modules (usually test-specific, for example guicey tests register additional guice module with restricted guice options (disableCircularProxies, requireExplicitBindings, requireExactBindingAnnotations))


Hooks could be activated on compiled application with a system property:, 

To simplify usage you can register hook alias:

    .hookAlias("alias1", MyHook1.class)
    .hookAlias("alias2", MyHook2.class)   

Now, hooks could be activated as:


Moreover, you will always see these aliases in application startup logs (to not forget about this abilities):

INFO  [2019-09-16 16:26:35,229] ru.vyarus.dropwizard.guice.hook.ConfigurationHooksSupport: Available hook aliases [ -Dguicey.hooks=alias ]: 



By default, guicey register diagnostic hook to easily activate dignostic reports on compiled application: