我正在使用 maven 构建 google appengine 应用程序。当客户端第一次请求访问的应用程序时 devserver 启动后,我们重新部署应用程序并重新执行 ServletListener。在这个过程中,servlet 上下文丢失了。我正在使用 servlet 上下文来存储连接的客户端列表。现在,因为应用程序已自动重新部署,并且清除了 servlet 上下文,所以我丢失了第一个客户端已连接的信息。servlet 上下文确实存储所有后续连接的客户端,直到开发服务器停止。
原因看起来像某些类文件正在更改,一旦开发服务器运行,就不应该更改。
2013 年 6 月 25 日上午 6:31:31 com.google.appengine.tools.development.JettyContainerService$2 filesChanged [INFO] INFO:文件已更改,正在重新加载 Web 应用程序。
以下是完整的日志
[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);
}
}
);
}
}