Google App Engine上的Spring Boot REST抛出502 [英] Spring Boot REST on Google App Engine throws 502

查看:82
本文介绍了Google App Engine上的Spring Boot REST抛出502的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为此苦苦挣扎了大约一个星期,而我在SO上所见到的任何东西都没有为我工作.我有一个基于Spring Boot构建的REST API,我正尝试将其部署到Google App Engine.在本地运行很好,当我在GAE模拟器上运行它时,它也可以正常运行.但是,一旦我使用mvn appengine:deploy进行部署,我便获得了成功的构建,但是当尝试使用端点时,我仅获得了502.我不确定日志在哪里,因此这确实是我的屁股.

I have been struggling with this for about a week and nothing I have seen on SO has worked for me. I have a REST API built on Spring Boot that I am trying to deploy to the Google App Engine. Running locally is fine and when I run it on the GAE emulator it works fine as well; however, once I deploy using mvn appengine:deploy I get a successful build but when trying the endpoints I only get a 502. I'm not sure where the logs are so this is really kicking my butt.

我的pom.xml:

My pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.mycompany.admin</groupId>
  <artifactId>admin-api</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.6.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
  </properties>

  <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <!-- Exclude this for deployment only -->
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- other project dependencies -->
    <dependency>
        <groupId>com.google.firebase</groupId>
        <artifactId>firebase-admin</artifactId>
        <version>5.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.10.2</version>
    </dependency>
    <!-- end other project specific dependencies -->

    <!-- Dependencies provided during deployment -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jul-to-slf4j</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <scope>provided</scope>
    </dependency>
    <!-- End dependencies for deployment -->

    <!-- Dependencies for local -->
    <!--        <dependency> -->
    <!--            <groupId>org.springframework.boot</groupId> -->
    <!--            <artifactId>spring-boot-starter-tomcat</artifactId> -->
    <!--            <scope>provided</scope> -->
    <!--        </dependency> -->
    <!-- End dependencies for local -->
  </dependencies>

  <build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>com.google.cloud.tools</groupId>
            <artifactId>appengine-maven-plugin</artifactId>
            <version>1.3.1</version>
            <configuration>
                <project>project-id-from-GAE-here</project
            </configuration>
        </plugin>
    </plugins>
  </build>
</project>

我的应用程序类是一个简单的带注释的@SpringBootApplication类.我有2个带有@RestController注释和简单@RequestMapping方法的控制器. REST控制器之一是用于/_ah/health端点的,该端点返回200,因为有一篇文章提到由于缺少运行状况检查端点而触发的持续重启.

My application class is a simple annotated @SpringBootApplication class. I have 2 controllers with annotation of @RestController and simple @RequestMapping methods. One of the REST controllers is for the /_ah/health endpoint that returns 200 since one post mentioned constant restarts being triggered by the lack of a healthcheck endpoint.

我有一个简单的application.yml用于我的价值注入,并在src/main/appengine

I have a simple application.yml for my value injections and created an app.yaml file placed in src/main/appengine

runtime: java
env: flexible
threadsafe: true
manual_scaling:
  instances: 1
handlers:
- url: /.*
  script: this field is required, but ignored
runtime_config:
  jdk: openjdk8

我对此完全不知所措.这是我的第一个GAE部署,希望还会有更多部署. (我还没有使用Docker,因为我在Windows 10机器上,当我在其上加载Docker时会中断.)

I am at a complete loss on this. It is my first GAE deployment with hopefully more to go. (I also am not using Docker yet since I am on a Windows 10 machine that breaks when I load Docker on it.)

更新 我确实注意到我忘记将项目ID放在maven插件下.一旦这样做,我就会得到关于找不到app.yaml的错误.我意识到,由于我使用的是灵活的环境,因此不需要appengine-web.xml,并且我将文件重命名为app.yml而不是app.yaml.我对此进行了更新,成功部署后仍然得到502.

UPDATE I did notice that I had forgotten to put my project id under the maven plugin. Once I did that I got errors about not finding the app.yaml. I realized that since I am using a flexible environment, I did not need the appengine-web.xml and I had my file misnamed as app.yml rather than app.yaml. I updated my question with this and I am still getting a 502 after a successful deployment.

推荐答案

我意识到我在GAE的试用期包括技术支持,因此我联系了他们.询问我的pom和app.yaml.他们的回应是将以下内容添加到我的app.yaml中:由于Java以消耗大量内存而闻名,因此开销过程消耗的内存超过大约0.4GB的值"

I realized my trial period with GAE included tech support so I contacted them. The asked for my pom and app.yaml. Their response was to add the following to my app.yaml "Since Java is known for consuming high memory usage, there is an overhead process consumed more than the approximate 0.4GB value"

resources:
  cpu: 2
  memory_gb: 2.3
  disk_size_gb: 10
  volumes:
  - name: ramdisk1
    volume_type: tmpfs
    size_gb: 0.5

他们还提供了以下链接供参考: https://cloud.google.com/appengine/docs/flexible/java/configuring-your-app-with-app-yaml#resource-settings

They also provided this link for reference: https://cloud.google.com/appengine/docs/flexible/java/configuring-your-app-with-app-yaml#resource-settings

完成此操作后,我的应用程序开始运行正常.

Once I did this, my application started working just fine.

编辑

如果您有一个简单的应用程序,请设置cpu:1,因为您需要按CPU小时计费,并且您的每日配额为28,而使用2个CPU则最终需要48个CPU小时.我在1个月内就花掉了300美元的免费信贷,因为他们的教程设置了一个RDB(80美元),该RDB不会被使用并且也不会杀死该项目.另外,请确保在部署新内容时删除旧版本,否则将向每个较高版本收取费用.

If you have a simple application, set cpu:1 since you get billed on CPU hours and your daily quota is 28 and with 2 CPUs you end up with 48 CPU hours. I burned through the free $300 credit in 1 month because their tutorials setup a RDB ($80) that doesn't get used and doesn't show to kill the project. Also make sure when deploying something new you delete the old versions or you will be charged for every version that is up.

这篇关于Google App Engine上的Spring Boot REST抛出502的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆