Google App Engine,Spring Boot应用不断重启

时间:2017-04-25 14:13:43

标签: google-app-engine spring-boot

我正在尝试构建一个Spring Boot REST API并将其托管在Google的App Engine上。我喜欢在我的工作项目中使用gradle,所以我选择使用Gradle。导航文档具有挑战性。

我终于得到了正确的gradle文件,以及正确的app.yaml配置。但我的春季启动应用程序只是继续在App Engine上重启。无论外部影响如何,它都会自动重启(点击端点时没有错误;应用程序的工作方式就像本地应用的那样......几秒钟内完成)。

我很难调试它。

以下是重新启动之前的最后几个日志。看起来SpringFrameworkServlet导致问题并重新启动?因为我的代码中没有任何Servlet,但我非常确定App Engine在其Java docker容器中有一些Servlet。

A  2017-04-25 14:01:26.604  INFO 1 --- [           main] o.s.d.r.w.BasePathAwareHandlerMapping    : Mapped "{[/profile/{repository}],methods=[GET],produces=[application/schema+json]}" onto public org.springframework.http.HttpEntity<org.springframework.data.rest.webmvc.json.JsonSchema> org.springframework.data.rest.webmvc.RepositorySchemaController.schema(org.springframework.data.rest.webmvc.RootResourceInformation)

A  2017-04-25 14:01:27.362  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup

A  2017-04-25 14:01:28.937  INFO 1 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)

A  2017-04-25 14:01:29.281  INFO 1 --- [           main] io.stevers.babli.BabliApplication        : Started BabliApplication in 34.136 seconds (JVM running for 39.899)

A  2017-04-25 14:01:30.978  INFO 1 --- [nio-8080-exec-9] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'

A  2017-04-25 14:01:30.982  INFO 1 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started

A  2017-04-25 14:01:31.126  INFO 1 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 144 ms

A  -XX:InitialHeapSize=514850816 -XX:MaxHeapSize=514850816 -XX:+ParallelRefProcEnabled -XX:+PrintCommandLineFlags -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC 

A  openjdk version "1.8.0_121"

A  OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-1~bpo8+1-b13)

A  OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)

A  

A  

的app.yaml

runtime: java
env: flex

service: springboot

runtime_config:  # Optional
  jdk: openjdk8

manual_scaling:
  instances: 1

的build.gradle

buildscript {
    ext {
        springBootVersion = '1.5.3.BUILD-SNAPSHOT'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
    }
    dependencies {
        classpath('com.google.cloud.tools:appengine-gradle-plugin:1.3.0')
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.google.cloud.tools.appengine'

version = '1.0.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-jersey')
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('com.h2database:h2')

    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.webjars:bootstrap:3.3.6')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

1 个答案:

答案 0 :(得分:2)

感谢两位github用户,我发现了我的问题。

由于运行状况检查失败,我的服务器正在重启。当您的服务未通过运行状况检查时,将重新启动它。所以解决这个问题的方法如下:

1)禁用健康检查。将其添加到您的app.yaml

health_check:
  enable_health_check: False

2)确保您的服务器为 /_ah/health 端点返回200或404。我为此添加了一个简单的REST控制器。

@RequestMapping("/_ah/health")
    public ResponseEntity<String> healthCheck() {
        return new ResponseEntity<>("Healthy", HttpStatus.OK);
    }

我希望这有助于其他人!我被困了一天半:(。