从Objectify v5过渡到v6 ObjectifyService.init()会引发NoClassDefFoundError

时间:2019-07-27 20:34:55

标签: java eclipse google-app-engine objectify

我正在将一个工作的google-appengine项目从objectify v5过渡到v6,该项目使用了新的Google Cloud数据存储端点。在我的侦听器类EntityRegistrar中,我叫ObjectifyService.init(),该类抛出NoClassDefFoudError。对象化v6.0.4和guava v18的Maven依赖关系看起来还可以,并且该项目使用Java8在Eclipse中可以很好地进行编译,但是我必须缺少一些东西。

尝试在本地google cloud beta数据存储区模拟器上运行时遇到相同的错误。

任何提示将不胜感激。

package org.chemvantage;

import java.util.Date;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.googlecode.objectify.ObjectifyService;

public class EntityRegistrar implements ServletContextListener {

     public void contextInitialized(ServletContextEvent servletContextEvent) {
        System.out.println("Starting up: " + new Date());

        ObjectifyService.init();   // line 15

        ObjectifyService.register(Assignment.class);
        ObjectifyService.register(BLTIConsumer.class);
    }
}

servlet没捕获到的异常

  

java.lang.NoClassDefFoundError:   com / googlecode / objectify / ObjectifyService,网址为   org.chemvantage.EntityRegistrar.contextInitialized(EntityRegistrar.java:15)     在   org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:843)     在   org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:533)     在   org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:816)     在   org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:345)     在   org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1406)     在   com.google.apphosting.runtime.jetty9.AppEngineWebAppContext.startWebapp(AppEngineWebAppContext.java:175)     在   org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1368)     在   org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778)     在   org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262)     在   org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:522)     在   com.google.apphosting.runtime.jetty9.AppEngineWebAppContext.doStart(AppEngineWebAppContext.java:120)     在   org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)     在   com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:240)     在   com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:178)     在   com.google.apphosting.runtime.jetty9.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:120)     在   com.google.apphosting.runtime.JavaRuntime $ RequestRunnable.dispatchServletRequest(JavaRuntime.java:722)     在   com.google.apphosting.runtime.JavaRuntime $ RequestRunnable.dispatchRequest(JavaRuntime.java:685)     在   com.google.apphosting.runtime.JavaRuntime $ RequestRunnable.run(JavaRuntime.java:655)     在   com.google.apphosting.runtime.JavaRuntime $ NullSandboxRequestRunnable.run(JavaRuntime.java:847)     在   com.google.apphosting.runtime.ThreadGroupPool $ PoolEntry.run(ThreadGroupPool.java:270)     在java.lang.Thread.run(Thread.java:748)

1 个答案:

答案 0 :(得分:0)

好的,感谢代表我挠头的人。我想我找到了答案:

为了处理异步数据存储操作(尤其是在后台保留的ofy()。sa ve()操作),必须包含以下Java类,该类扩展了ObjectifyFilter。

package org.chemvantage;

import javax.servlet.annotation.WebFilter;

import com.googlecode.objectify.ObjectifyFilter;

/**
 * Filter required by Objectify to clean up any thread-local transaction contexts and pending
 * asynchronous operations that remain at the end of a request.
 */
@WebFilter(urlPatterns = {"/*"})
public class ObjectifyWebFilter extends ObjectifyFilter {}

这是对web.xml文件中ObjectifyFilter的必需定义的补充。

<web-app>
  <filter>
    <filter-name>ObjectifyFilter</filter-name>
    <filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>ObjectifyFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

您都需要,尽管这似乎违反直觉。我通过删除一个然后替换并删除另一个来检查它。将其放入upgrading from v5 to v6的Objectify说明中会很有帮助。