google-app-engine - 谷歌应用引擎 + 对象化 : Register object once?

标签 google-app-engine jsp objectify

我最近使用 App Engine 进行了 objectify,但我在为 objectify 多次注册类时遇到了问题。在Eclipse开发中,每次刷新localhost都会重新编译运行,注册学生的脚本运行了多次,刷新一次就崩溃了。

<%
//In my main.jsp file, which is the main interactive html page
ObjectifyService.register(Object.class);
%>

如何确保此脚本只运行一次?有没有办法检查一个类是否已向 objectify 注册?我按照另一个 stackoverflow 线程的建议执行以下操作:

public class Object {
    ...
    static {
        ObjectifyService.register(Object.class);
    }
    ...
}

这给了我一个不同的错误。我该如何解决这个问题?

最佳答案

把它放在你的 ServletContextListener 上,特别是在 contextInitialized() Hook 上。这将确保 Objectify 注册代码仅在服务器预热时执行一次。

关于google-app-engine - 谷歌应用引擎 + 对象化 : Register object once?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9028717/

相关文章:

java - 根据单独表中的统计数据对用户列表进行排序

python - Unity3d - 在 Google App Engine 上托管

java - 未使用 getById() 获取数据存储强一致性读取

node.js - 在 Compute Engine 上连接 Redis 时 Google Cloud App Engine 标准环境 Node JS 连接超时

java - Jersey Guice JSP如何?

java - 404 请求的资源不可用 Eclipse/Tomcat

javascript - 如何将图像 (byte[]) 从 servlet 发送到 HTML 页面

java - 为什么我得到 Only ancestor queries are allowed inside transactions 错误

java - 如何从 GAE servlet 发送 HTTPS 请求?

python - 错误,“[错误] 33#33 : *92500 connect() failed (111: Connection refused) while connecting to upstream, 客户端 : 216. 58.212.244,服务器:#1906