Google App Engine、Spring Boot 应用程序不断重启

Ste*_*ers 4 google-app-engine spring-boot

我正在尝试构建一个 Spring Boot REST API 并将其托管在 Google 的 App Engine 上。我在工作中的项目中更喜欢 gradle,所以我选择使用 Gradle。文档很难浏览。

我终于得到了正确的 gradle 文件和正确的 app.yaml 配置。但是我的 Spring Boot 应用程序只是在 App Engine 上不断重启。无论任何外部影响如何,它都会自动重新启动(点击端点时没有错误;该应用程序就像在本地一样工作......持续几秒钟)。

我很难调试它。

这是再次重新启动之前的最后几条日志。看起来 SpringFrameworkServlet 导致了问题并使其重新启动?因为我的代码中没有任何 Servlet,但我很确定 App Engine 已经将 Servlet 融入到它的 Java docker 容器中。

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  
Run Code Online (Sandbox Code Playgroud)

应用程序.yaml

runtime: java
env: flex

service: springboot

runtime_config:  # Optional
  jdk: openjdk8

manual_scaling:
  instances: 1
Run Code Online (Sandbox Code Playgroud)

构建.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')
}
Run Code Online (Sandbox Code Playgroud)

Ste*_*ers 6

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

由于运行状况检查失败,我的服务器正在重新启动。当您的服务未通过健康检查时,它会重新启动。因此,解决此问题的选项如下:

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

health_check:
  enable_health_check: False
Run Code Online (Sandbox Code Playgroud)

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

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

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