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

时间:2013-06-25 06:42:11

标签: java google-app-engine guice devserver servletcontextlistener

我正在使用maven来构建谷歌appengine应用程序。在客户端在第一次请求时访问应用程序时,devserver启动后,应用程序重新部署并重新执行ServletListener。在此过程中,servlet上下文丢失。我正在使用servlet上下文来存储连接的客户端列表。现在因为应用程序被自动重新部署并且servlet上下文被清除,所以我丢失了第一个客户端连接的信息。 servlet上下文会存储连接的所有后续客户端,直到dev服务器停止。

原因似乎是某个类文件发生了变化,一旦devserver运行就不应该这样。

  

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);

                }
            }
    );
}
}

1 个答案:

答案 0 :(得分:1)

经过一些谷歌搜索后,我发现这是因为在第一个请求上创建了本地数据库文件,并且扫描了目标目录的更改,导致应用程序重新加载。

找到了几个workarrounds

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

        -Dappengine.generated.dir = / TMP /布拉布拉  

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

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

    我仍然愿意接受永久解决方案,直到Google修复此问题

    Source