Guice 4.0-beta5不适用于Sitebricks 0.8.10

时间:2015-02-22 21:14:30

标签: google-app-engine servlets guice guice-servlet sitebricks

我刚尝试使用最新版本的Guice和Sitebricks(4.0-beta5)和(0.8.10)在Sitebricks网站上部署GAE示例HelloWorld应用程序,并且注入失败。这是Google App Engine日志显示的内容:

Uncaught exception from servlet
com.google.inject.CreationException: Unable to create injector, see the following errors:

1) An exception was caught and reported. Message: Unable to get members for class com.google.inject.multibindings.Multibinder$RealMultibinder
  at com.google.sitebricks.SitebricksModule.configure(SitebricksModule.java:82) (via modules: com.myapp.servlet.MyGuiceServletConfig$1 -> com.google.inject.multibindings.Multibinder$RealMultibinder)

2) No implementation for java.util.Set<com.google.sitebricks.conversion.Converter> was bound.
  at com.google.sitebricks.SitebricksModule.configure(SitebricksModule.java:82) (via modules: com.myapp.servlet.MyGuiceServletConfig$1 -> com.google.inject.multibindings.Multibinder$RealMultibinder)

2 errors
    at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:448)
    at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:155)
    at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107)
    at com.google.inject.Guice.createInjector(Guice.java:96)
    at com.google.inject.Guice.createInjector(Guice.java:73)
    at com.google.inject.Guice.createInjector(Guice.java:62)
    at com.myapp.servlet.MyGuiceServletConfig.getInjector(MyGuiceServletConfig.java:13)
    at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:47)
    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:199)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:174)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:134)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:527)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:220)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
    at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.SecurityException: Unable to get members for class com.google.inject.multibindings.Multibinder$RealMultibinder
    at com.google.appengine.runtime.Request.process-67803a1bdc416a76(Request.java)
    at java.lang.Class.getDeclaredFields(Class.java:218)
    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.google.sitebricks.SitebricksModule.configure(SitebricksModule.java:82)
    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:73)
    at com.google.inject.Guice.createInjector(Guice.java:62)
    at com.myapp.servlet.MyGuiceServletConfig.getInjector(MyGuiceServletConfig.java:13)
    at com.google.inject.servlet.GuiceServletContextListener.contextInitialized(GuiceServletContextListener.java:47)
    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:220)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
    ... 1 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    ... 35 more
Caused by: java.lang.NoClassDefFoundError: Lcom/google/inject/internal/util/$ImmutableList;
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2383)
    ... 35 more
Caused by: java.lang.ClassNotFoundException: com.google.inject.internal.util.$ImmutableList
    at com.google.appengine.runtime.Request.process-67803a1bdc416a76(Request.java)
    ... 35 more

在我看来,com.google.inject.util.internal包在4.0-beta5中完全丢失,这就是造成ClassNotFoundException的原因。使用3.0而不是4.0-beta5解决了这个问题。

是否有可能以某种方式使用两者的最新版本?考虑到两者都是“谷歌出生的项目”,我很惊讶它们是不兼容的。 Sitebricks有更好的替代方案吗?

P.S。在旁注中,sitebricks.org已经关闭,即使最近有一些(2015年1月)提交......项目是否仍然得到积极维护?

1 个答案:

答案 0 :(得分:0)

对缺少的类的调用来自Guice包之外(特别是来自AppEngine包)。从Guice和Sitebricks中获取最新的代码表明他们不会尝试在任何地方引用这个丢失的包(它们都使用Guava的ImmutableList)。您使用的是哪个版本的AppEngine?