IAmYourFaja IAmYourFaja - 10 months ago 65
Java Question

Guice: how to print a module's bindings?

I have been staring at a nasty bug in my code for the last 2 days, surrounding my Guice module and the bindings I've declared inside of it. I have about 20 bindings declared in my module, and only 1 of them is not working.

I have exhausted every option here and am wondering if there's a

-like method in the Guice library where I can print out a String version of all a module's bindings; either that or somehow get Guice to log what's its doing whenever it reads in my defective binding.

Answer Source
Injector injector = Guice.createInjector(myModuleInstance);
Map<Key<?>,Binding<?>> map = injector.getBindings();
for(Entry<Key<?>, Binding<?>> e : map.entrySet()) {
    System.out.println(e.getKey() + ": " + e.getValue());