java为什么Guice抛出NoSuchMethodError?
这是Google Guice调用代码:
public static ContainerRunner forInjector(Injector injector) {
return (ContainerRunner)injector.getInstancefaultContainerRunner.class);
}
public static ContainerRunner forModules(Iterable<? extends Module> modules) {
return forInjector(Guice.createInjector(modules));
}
这是个例外:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.inject.internal.Initializer.requestInjection(Lcom/google/inject/internal/InjectorImpl;Ljava/lang/Object;Lcom/google/inject/Binding;Ljava/lang/Object;Ljava/util/Set;)Lcom/google/inject/internal/Initializable;
at com.google.inject.internal.BindingProcessor$1.visit(BindingProcessor.java:108)
at com.google.inject.internal.BindingProcessor$1.visit(BindingProcessor.java:70)
at com.google.inject.internal.ProviderInstanceBindingImpl.acceptTargetVisitor(ProviderInstanceBindingImpl.java:62)
at com.google.inject.internal.BindingProcessor.visit(BindingProcessor.java:70)
at com.google.inject.internal.BindingProcessor.visit(BindingProcessor.java:43)
at com.google.inject.internal.BindingImpl.acceptVisitor(BindingImpl.java:93)
at com.google.inject.internal.AbstractProcessor.process(AbstractProcessor.java:56)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:186)
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:73)
at com.baml.gmt.xasf.container.ContainerRunners.forModules(ContainerRunners.java:39)
我的问题是消息没有告诉我缺少哪种特定方法。有没有一个好的调试方法?这会是Maven的可传递依赖性问题吗强>
# 1 楼答案
事实证明,当我在Unix环境中执行时,lib目录中的文件存在权限问题。我一更改权限,它就通过了这个Guice错误。从我的粘贴经验来看,这个Guice错误几乎总是由于依赖性问题造成的。但Guice并没有给出更具体、更具描述性的错误消息
# 2 楼答案
它准确地告诉你缺少什么方法。它是:
com.google.inject.internal.Initializer
考虑到方法签名最后一次更改Five years ago,您几乎肯定会遇到某种构建问题,使得方法不知何故不在类路径中。您没有给我们提供足够的信息,无法进一步调试