【问题标题】:503 Service Unavailable for google endpoints503 服务对谷歌端点不可用
【发布时间】:2015-05-01 03:42:51
【问题描述】:

我正在使用端点尝试为我的 Web 应用程序创建一个患者实体。当我尝试运行 API 时,我不断收到以下错误代码。

    503 Service Unavailable

- Show headers -

    {
     "error": {
      "errors": [
   {
    "domain": "global",
    "reason": "backendError",
    "message": "java.lang.IllegalStateException: You have not started an Objectify context. You are probably missing the ObjectifyFilter. If you are not running in the context of an http request, see the ObjectifyService.run() method."
   }
  ],
  "code": 503,
  "message": "java.lang.IllegalStateException: You have not started an Objectify context. You are probably missing the ObjectifyFilter. If you are not running in the context of an http request, see the ObjectifyService.run() method."
 }
}

我知道这与静态 ofy 文件有关,我不确定如何向其中添加过滤器。 这是我的静态对象化文件的代码。

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;


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

然后我在API类中使用这个方法调用ofy文件

ofy().save().entity(patient).now();

【问题讨论】:

    标签: java google-app-engine google-cloud-endpoints objectify


    【解决方案1】:

    将此代码添加到您的web.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>
    

    【讨论】:

    • 非常感谢@tomrozb。现在它说明了一些关于注册我从中获取信息的类的内容,是否有我需要粘贴到 web.xml 中的 objectify register 方法?
    • 没关系,我在静态方法中添加了正确的语句。对于遇到这些问题的其他人,我必须将此代码输入到 ofyService 类static{ ObjectifyService.register(Patient.class); }
    猜你喜欢
    • 2014-10-26
    • 2019-02-22
    • 2021-10-27
    • 2015-10-20
    • 2017-08-23
    • 2015-06-21
    • 1970-01-01
    • 2019-10-30
    • 2015-01-14
    相关资源
    最近更新 更多