java - 从 Objectify v5 转换到 v6 ObjectifyService.init() 会抛出 NoClassDefFoundError

标签 java eclipse google-app-engine objectify

我正在将一个正在运行的 google-appengine 项目从 objectify v5 过渡到 v6,该项目使用新的 Google Cloud 数据存储端点。在我的监听器类 EntityRegistrar 类中,我调用 ObjectifyService.init() ,它会抛出 NoClassDefFoudError。 objectify 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 at org.chemvantage.EntityRegistrar.contextInitialized(EntityRegistrar.java:15) at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:843) at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:533) at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:816) at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:345) at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1406) at com.google.apphosting.runtime.jetty9.AppEngineWebAppContext.startWebapp(AppEngineWebAppContext.java:175) at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1368) at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778) at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262) at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:522) at com.google.apphosting.runtime.jetty9.AppEngineWebAppContext.doStart(AppEngineWebAppContext.java:120) at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) at com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:240) at com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:178) at com.google.apphosting.runtime.jetty9.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:120) at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchServletRequest(JavaRuntime.java:722) at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.dispatchRequest(JavaRuntime.java:685) at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:655) at com.google.apphosting.runtime.JavaRuntime$NullSandboxRequestRunnable.run(JavaRuntime.java:847) at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:270) at java.lang.Thread.run(Thread.java:748)

最佳答案

好的,感谢所有为我的问题绞尽脑汁的人。我想我找到了答案:

为了处理异步数据存储操作(尤其是留在后台的 ofy().save() 操作),必须包含以下 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 指令中会很有帮助。 .

关于java - 从 Objectify v5 转换到 v6 ObjectifyService.init() 会抛出 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57235863/

相关文章:

java - 是否可以编写一个泛型函数来提取泛型对象中的对象?

java - Java中二维数组的声明和格式

java - 如何从命令行运行带有包的java项目?

java - 在 App Engine servlet 中存储已用 token 列表 - java

google-app-engine - Google Cloud 未正确安装软件包

java - 扫描仪问题,输入信息不起作用

php - Eclipse PDT 不建议所有的php函数

java.lang.OutOfMemory错误: Java heap space on using ArrayLists

java - 如何在 Spring STS 中查看 @Autowired bean 的 Bean 图?

python - 使用 web2py 查找在 Google 应用引擎中热链接的网站的域名