我正在使用端点尝试为我的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();
答案 0 :(得分: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>