我已经为此苦苦挣扎了大约一个星期,但我在 SO 上看到的任何东西都没有为我工作。我有一个基于 Spring Boot 构建的 REST API,我正在尝试将其部署到 Google App Engine。在本地运行很好,当我在 GAE 模拟器上运行它时也可以正常运行;但是,一旦我使用部署,mvn appengine:deploy
我得到了一个成功的构建,但是在尝试端点时,我只得到一个 502。我不确定日志在哪里,所以这真的让我很恼火。
我的 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 的端点,因为一篇文章提到由于缺少运行状况检查端点而触发了持续重启。
我有一个简单的 application.yml 用于我的值注入,并创建了一个app.yaml
放置在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 时它会中断。)
更新 我确实注意到我忘记将我的项目 ID 放在 maven 插件下。一旦我这样做了,我就会收到关于找不到 app.yaml 的错误。我意识到,由于我使用的是灵活的环境,因此我不需要 appengine-web.xml,而且我的文件被误命名为 app.yml 而不是 app.yaml。我用这个更新了我的问题,成功部署后我仍然得到 502。