我一直在尝试使用Objectify为我的Endpoint项目中的工作准备好请求,但似乎没有任何东西工作。我错过了什么吗?我尝试了两种方法:
servlet:
public class WarmUpServ extends HttpServlet {
static {
ObjectifyService.factory().register(CounterEnt.class);
ObjectifyService.factory().register(CounterShard.class);
}
@Override
public void init() throws ServletException {
super.init();
}
@Override
public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException,IOException {
}
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}web.xml
<servlet>
<servlet-name>warm-up</servlet-name>
<servlet-class>com.myapp.backend.WarmUpServ</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>warm-up</servlet-name>
<url-pattern>/war-up</url-pattern>
</servlet-mapping>我也试过一个听众:
public class WarmUpServListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
ObjectifyService.factory().register(CounterEnt.class);
ObjectifyService.factory().register(CounterShard.class);
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
}
}web.xml
<listener>
<listener-class>com.myapp.backend.WarmUpServListener</listener-class>
</listener>注意:我需要以这种方式注册我的实体,因为我有一个直接使用ObjectifyService的依赖项。
发布于 2017-05-08 16:01:08
热身请求并不一定会被提出。
https://cloud.google.com/appengine/docs/standard/java/warmup-requests/
如果为应用程序启用了热身请求,App将尝试检测应用程序何时需要新实例,并启动热身请求以初始化新实例。然而,这些检测尝试并不是在每种情况下都有效。因此,您可能会遇到加载请求,即使在应用程序中启用了热身请求。例如,如果您的应用程序不提供任何流量,则对应用程序的第一个请求将始终是加载请求,而不是热身请求。
使用ServletContextListener代替;在每次实例启动时都会调用一次。
https://stackoverflow.com/questions/43839149
复制相似问题