【问题标题】:Google App Engine, Spring Boot app keeps restartingGoogle App Engine,Spring Boot 应用不断重启
【发布时间】:2017-04-25 14:13:42
【问题描述】:

我正在尝试构建 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  

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')
}

【问题讨论】:

  • 我在使用 jhipster 生成的标准应用程序引擎和 Spring Boot 应用程序方面面临同样的问题。当我尝试在本地系统上运行 appengine:run 时,应用程序由 maven 插件多次启动,然后由于数据源实例已经启动而失败。任何人都知道它可能有什么问题吗?
  • 我忘了在上面的评论中提到我最近添加了谷歌搜索 API。并且要调试它,我需要在本地运行它。相同的应用程序在云上运行没有任何问题。
  • 我通过将扩展实例减少到 1 解决了这个问题。这实际上不是问题。由于 appengine-web.xml 中指定的缩放,它正在初始化

标签: google-app-engine spring-boot


【解决方案1】:

感谢两位 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);
    }

我希望这对其他人有帮助!我在这个问题上卡了一天半:(。

【讨论】:

  • 如果我使用enable_health_check: False,我真的需要创建/_ah/health 端点吗?要求这个似乎很奇怪。
  • 抱歉不清楚,我说它们是表示“非此即彼”的选项。我将其更新为明确的。
  • 这不再有效,因为旧的运行状况检查已被弃用并被拆分运行状况检查所取代。 cloud.google.com/appengine/docs/flexible/custom-runtimes/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-02-02
  • 2019-05-18
  • 1970-01-01
  • 2021-11-21
  • 2019-05-04
  • 2019-03-16
  • 2021-02-25
相关资源
最近更新 更多