Governator integration is broken in dropwizard-guice 0.8.0
Closed this issue · 2 comments
Governator is incompatible with the latest dropwizard (0.8.0), so the mentioned example in the README no longer works.
If we attempt to exclude Guice from Governator, we see the following stack trace:
Exception in thread "main" java.lang.NoClassDefFoundError: Lcom/google/inject/internal/util/$ImmutableList;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2499)
at java.lang.Class.getDeclaredFields(Class.java:1811)
at com.google.inject.spi.InjectionPoint.getInjectionPoints(InjectionPoint.java:661)
at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:366)
at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:385)
at com.google.inject.internal.BindingBuilder.toProvider(BindingBuilder.java:110)
at com.google.inject.internal.BindingBuilder.toProvider(BindingBuilder.java:100)
at com.google.inject.internal.BindingBuilder.toProvider(BindingBuilder.java:43)
at com.google.inject.multibindings.Multibinder$RealMultibinder.configure(Multibinder.java:269)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:253)
at com.google.inject.multibindings.Multibinder.newSetBinder(Multibinder.java:115)
at com.google.inject.multibindings.Multibinder.newSetBinder(Multibinder.java:124)
at com.netflix.governator.guice.BootstrapBinder.(BootstrapBinder.java:65)
at com.netflix.governator.guice.InternalBootstrapModule.configure(InternalBootstrapModule.java:88)
at com.google.inject.AbstractModule.configure(AbstractModule.java:62)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:253)
at com.google.inject.spi.Elements.getElements(Elements.java:108)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:135)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:84)
at com.netflix.governator.guice.LifecycleInjector.(LifecycleInjector.java:418)
at com.netflix.governator.guice.LifecycleInjectorBuilderImpl.build(LifecycleInjectorBuilderImpl.java:309)
at com.gordysc.GovernatorInjectorFactory.create(GovernatorInjectorFactory.java:15)
at com.hubspot.dropwizard.guice.GuiceBundle.initInjector(GuiceBundle.java:105)
at com.hubspot.dropwizard.guice.GuiceBundle.initialize(GuiceBundle.java:96)
at io.dropwizard.setup.Bootstrap.addBundle(Bootstrap.java:142)
at com.gordysc.ExampleApplication.initialize(ExampleApplication.java:22)
at io.dropwizard.Application.run(Application.java:71)
at com.gordysc.ExampleApplication.main(ExampleApplication.java:32)
Caused by: java.lang.ClassNotFoundException: com.google.inject.internal.util.$ImmutableList
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 31 more
So, Governator depends on Guice 3.0 for ImmutableList:
http://grepcode.com/file/repo1.maven.org/maven2/com.google.inject/guice/3.0/com/google/inject/internal/util/ImmutableList.java?av=f
Note: This class no longer exists in Guice 4.0-beta5.
However, dropwizard-guice depends on Guice 4.0-beta5. You can see this by not excluding Guice from Governator (using 3.0), you'll see the stack trace:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.inject.binder.AnnotatedBindingBuilder.toProvider(Ljavax/inject/Provider;)Lcom/google/inject/binder/ScopedBindingBuilder;
at com.squarespace.jersey2.guice.InternalJerseyModule.configure(InternalJerseyModule.java:58)
at com.google.inject.AbstractModule.configure(AbstractModule.java:59)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
at com.google.inject.AbstractModule.install(AbstractModule.java:118)
at com.squarespace.jersey2.guice.BootstrapModule.configure(BootstrapModule.java:44)
at com.google.inject.AbstractModule.configure(AbstractModule.java:59)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
at com.google.inject.AbstractModule.install(AbstractModule.java:118)
at com.hubspot.dropwizard.guice.JerseyModule.configureServlets(JerseyModule.java:15)
at com.google.inject.servlet.ServletModule.configure(ServletModule.java:55)
at com.google.inject.AbstractModule.configure(AbstractModule.java:59)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
at com.google.inject.spi.Elements.getElements(Elements.java:101)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:133)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
at com.google.inject.internal.InjectorImpl.createChildInjector(InjectorImpl.java:217)
at com.netflix.governator.guice.LifecycleInjector.createChildInjector(LifecycleInjector.java:327)
at com.netflix.governator.guice.LifecycleInjector.createInjector(LifecycleInjector.java:394)
at com.netflix.governator.guice.LifecycleInjector.createInjector(LifecycleInjector.java:348)
at com.gordysc.GovernatorInjectorFactory.create(GovernatorInjectorFactory.java:15)
at com.hubspot.dropwizard.guice.GuiceBundle.initInjector(GuiceBundle.java:105)
at com.hubspot.dropwizard.guice.GuiceBundle.initialize(GuiceBundle.java:96)
at io.dropwizard.setup.Bootstrap.addBundle(Bootstrap.java:142)
at com.gordysc.ExampleApplication.initialize(ExampleApplication.java:22)
at io.dropwizard.Application.run(Application.java:71)
at com.gordysc.ExampleApplication.main(ExampleApplication.java:32)
So, dropwizard-guice depends on a method added in Guice 4.0-beta5:
http://grepcode.com/file/repo1.maven.org/maven2/com.google.inject/guice/4.0-beta5/com/google/inject/binder/LinkedBindingBuilder.java#LinkedBindingBuilder.toProvider%28java.lang.Class%29
Based on the stack trace it looks like you might be mixing guice 4.0-beta5 with guice-multibindings 3. If that's the case, can you try with guice and all guice extensions at 4.0-beta5 and let me know if you still hit an issue?
Thanks for the blistering fast response @HiJon89 !
Great call, somehow missed that. So, in summary, for the latest version of Governator at this time (1.3.3), I have to exclude the following:
org.hibernate:hibernate-validator
com.google.guava:guava
com.google.inject:inject
com.google.inject.extensions:guice-multibindings