gpt4 book ai didi

java - appengine devserver 在第一次请求时重新部署应用程序

转载 作者:行者123 更新时间:2023-12-01 14:24:11 25 4
gpt4 key购买 nike

我正在使用 Maven 来构建 google appengine 应用程序。开发服务器启动后,当客户端在第一个请求时访问应用程序时,我们会重新部署应用程序并重新执行 ServletListener。在此过程中,Servlet 上下文会丢失。我正在使用 servlet 上下文来存储连接的客户端列表。现在,由于应用程序已自动重新部署且 servlet 上下文已清除,因此我丢失了第一个客户端已连接的信息。 servlet 上下文确实存储所有后续连接的客户端,直到开发服务器停止。

原因看起来是某些类文件发生了更改,而一旦开发服务器运行,就不应该发生更改。

Jun 25, 2013 6:31:31 AM com.google.appengine.tools.development.JettyContainerService$2 filesChanged [INFO] INFO: A file has changed, reloading the web application.

以下是完整日志

[INFO] 
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ NoteWebApp ---
[INFO] Packaging webapp
[INFO] Assembling webapp [NoteWebApp] in [/Users/saghosh/dev/NoteWebApp/target/NoteWebApp]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/saghosh/dev/NoteWebApp/src/main/webapp]
[INFO] Webapp assembled in [140 msecs]
[INFO] Building war: /Users/saghosh/dev/NoteWebApp/target/NoteWebApp.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO]
[INFO] <<< appengine-maven-plugin:1.8.1:devserver (default-cli) @ NoteWebApp <<<
[INFO]
[INFO] --- appengine-maven-plugin:1.8.1:devserver (default-cli) @ NoteWebApp ---
[INFO]
[INFO] Google App Engine Java SDK - Running Development Server
[INFO]
[INFO] Retrieving Google App Engine Java SDK from Maven
[INFO] Running /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java -XstartOnFirstThread -javaagent:/Users/saghosh/.m2/repository/com/google/appengine/appengine-java-sdk/1.8.1/appengine-java-sdk/appengine-java-sdk-1.8.1/lib/agent/appengine-agent.jar -Xbootclasspath/p:/Users/saghosh/.m2/repository/com/google/appengine/appengine-java-sdk/1.8.1/appengine-java-sdk/appengine-java-sdk-1.8.1/lib/override/appengine-dev-jdk-overrides.jar -Dappengine.fullscan.seconds=5 -classpath /Users/saghosh/.m2/repository/com/google/appengine/appengine-java-sdk/1.8.1/appengine-java-sdk/appengine-java-sdk-1.8.1/lib/appengine-tools-api.jar com.google.appengine.tools.development.DevAppServerMain --allow_remote_shutdown /Users/saghosh/dev/NoteWebApp/target/NoteWebApp
[INFO] 2013-06-25 12:01:16.813 java[15483:407] [Java CocoaComponent compatibility mode]: Enabled
[INFO] 2013-06-25 12:01:16.814 java[15483:407] [Java CocoaComponent compatibility mode]: Setting timeout for SWT to 0.100000
[INFO] Jun 25, 2013 12:01:18 PM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml
[INFO] INFO: Successfully processed /Users/saghosh/dev/NoteWebApp/target/NoteWebApp/WEB-INF/appengine-web.xml
[INFO] 2013-06-25 12:01:18.717:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
[INFO] Jun 25, 2013 12:01:18 PM com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml
[INFO] INFO: Successfully processed /Users/saghosh/dev/NoteWebApp/target/NoteWebApp/WEB-INF/web.xml
[INFO] 2013-06-25 12:01:18.978:INFO::jetty-6.1.x
[INFO] ****** Scan complete ******
[INFO] 2013-06-25 12:01:21.081:INFO::Started SelectChannelConnector@127.0.0.1:8080
[INFO] Jun 25, 2013 6:31:21 AM com.google.appengine.tools.development.JettyContainerService startHotDeployScanner
[INFO] INFO: Full scan of the web app in place every 5s.
[INFO] Jun 25, 2013 6:31:21 AM com.google.appengine.tools.development.AbstractServer startup
[INFO] INFO: Server default is running at http://localhost:8080/
[INFO] Jun 25, 2013 6:31:21 AM com.google.appengine.tools.development.AbstractServer startup
[INFO] INFO: The admin console is running at http://localhost:8080/_ah/admin
[INFO] Jun 25, 2013 6:31:21 AM com.google.appengine.tools.development.DevAppServerImpl start
[INFO] INFO: Dev App Server is now running
[INFO] Jun 25, 2013 6:31:27 AM com.google.appengine.api.datastore.dev.LocalDatastoreService init
[INFO] INFO: Local Datastore initialized:
[INFO] Type: Master/Slave
[INFO] Storage: /Users/saghosh/dev/NoteWebApp/target/NoteWebApp/WEB-INF/appengine-generated/local_db.bin
[INFO] Jun 25, 2013 6:31:27 AM com.google.appengine.api.datastore.dev.LocalDatastoreService load
[INFO] INFO: The backing store, /Users/saghosh/dev/NoteWebApp/target/NoteWebApp/WEB-INF/appengine-generated/local_db.bin, does not exist. It will be created.
[INFO] Client trying to connect with ID 0354c90b-46cd-46d2-81d1-b57cd311a7a2Initialising client list
[INFO] New client connected with ID 0354c90b-46cd-46d2-81d1-b57cd311a7a2
[INFO] Jun 25, 2013 6:31:31 AM com.google.appengine.tools.development.JettyContainerService$2 filesChanged
[INFO] INFO: A file has changed, reloading the web application.
[INFO] Jun 25, 2013 6:31:31 AM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml
[INFO] INFO: Successfully processed /Users/saghosh/dev/NoteWebApp/target/NoteWebApp/WEB-INF/appengine-web.xml
[INFO] Jun 25, 2013 6:31:31 AM com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml
[INFO] INFO: Successfully processed /Users/saghosh/dev/NoteWebApp/target/NoteWebApp/WEB-INF/web.xml
[INFO] ****** Scan complete ******

以下是servlet上下文监听器

public class MyGuiceServletConfig extends GuiceServletContextListener {

@Override
protected Injector getInjector() {
return Guice.createInjector(
//Keep sending Guice the modules
new SitebricksModule() {
@Override
protected void configureSitebricks() {
scan(NotebookService.class.getPackage());
//Should change this to logger, this is just to proove that
//sitebrick scans the classes for annotations like @At etc.
System.out.println("****** Scan complete ******");
}
}
, new ServletModule() {
@Override
protected void configureServlets() {
//Servlet classes have to be singleton to be consistent with servlet specification
//In tranditional cases web.xml config tell the container to do so I guess.
bind(com.neil.NotebookServlet.class).in(Singleton.class);
//Analogous to typcial servlet URL mappings
serve("/servlet").with(com.neil.NotebookServlet.class);

bind(com.neil.TrackerServlet.class).in(Singleton.class);
serve("/_ah/channel/connected/").with(com.neil.TrackerServlet.class);

bind(com.neil.TrackerServlet1.class).in(Singleton.class);
serve("/_ah/channel/disconnected/").with(com.neil.TrackerServlet1.class);

}
}
);
}
}

最佳答案

经过一番谷歌搜索后,我发现发生这种情况是因为在第一个请求时创建了本地数据库文件,并且扫描了目标目录是否有更改,从而导致应用程序重新加载。

找到了几个解决方法

  1. 将 db 目录更改为外部目标目录。但如果有其他变化,它将再次重新加载。

    -Dappengine. generated.dir=/tmp/blabla

2.禁用自动扫描,但作为开发人员,您希望避免每次更改代码时再次停止和启动服务器。

<jvmFlags>
<jvmFlag>-Dappengine.fullscan.seconds=-1</jvmFlag>
</jvmFlags>

我仍然愿意接受永久解决方案,直到谷歌解决这个问题

Source

关于java - appengine devserver 在第一次请求时重新部署应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17290780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com