google-app-engine - 由于缺少 ObjectifyFilter,Objectify 5.1 上下文未启动错误

标签 google-app-engine objectify

使用最新版本的 Objectify (5.1),当我尝试访问 ofy() 方法时出现以下错误

您还没有启动 Objectify 上下文。您可能缺少 ObjectifyFilter。如果您没有在 http 请求的上下文中运行,请参阅 ObjectifyService.run() 方法。

我从 appengine web 应用程序运行它,相同的代码和配置在旧版本中运行良好

以下是我的配置,类似于objectify文档中提供的例子

网络.xml

<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>

OfyService类

public class OfyService {

static {
    long start = System.currentTimeMillis();

    factory().register(User.class);

    log.info(" Entity Registration took : {} ms", (System.currentTimeMillis() - start));
}

public static Objectify ofy() {
    return ObjectifyService.ofy();
}

public static ObjectifyFactory factory() {
    return (ObjectifyFactory) ObjectifyService.factory();
}
}

但我确实定义了 ObjectifyFilter ,知道为什么我会收到此错误吗?我该如何解决?

谢谢!

更新:

我已经将 objectify 版本更新到 v5.1.5,但问题仍然没有解决,是否有更新?

最佳答案

确保您的 StartupActions 类如下所示:

@Start(order=100)
public void generateDummyDataWhenInTest() {
    if (ninjaProperties.isDev()) {
        try (Closeable closeable = ObjectifyService.begin()) {
            ObjectifyProvider.setup();
        } catch (IOException ex) {
            Logger.getLogger(StartupActions.class.getName()).log(Level.SEVERE, null, ex);
        } 
    }
}

我们早就应该在原型(prototype)中修复它,但它在优先级列表中的排名并不高。如果你能插入 PR 就太棒了 :)

关于google-app-engine - 由于缺少 ObjectifyFilter,Objectify 5.1 上下文未启动错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26577029/

相关文章:

java - 无法使用 Spring Security 保护 AngularJS 页面

google-app-engine - 从外部 URL 加载 Freemarker 模板

google-app-engine - 转到 GAE 错误 : can't find '__main__' module (Win 8. 1)

java - 使用 Google App Engine 数据存储区中的实体列表

java - GWT 请求工厂 : can not get a list of valueproxy inside an EntityProxy

java - objectify/google 应用引擎中的外键

google-app-engine - 在 Google App Engine 数据模型中进行 'OR' 查询

google-app-engine - 尝试为托管VM拉取google/appengine-java镜像时,如何克服此500服务器内部错误?

java - Google Cloud Datastore 中的二维数组对象

java - Appengine Key 序列化临时 appIdNamespace