Spring 部署到 GAE 时启动导致 WebAppContext 错误

Spring Boot causes WebAppContext error when deployed to GAE

我正在为个人项目构建一个 REST API,使用 Spring Boot 来这样做,然后部署到 Google App Engine。该项目在本地编译和运行没有任何问题,我可以毫无构建错误地部署到 GAE。 但是,当我在部署到 GAE 后导航到我的 URI 时,抛出 404 并显示以下消息:

No context on this server matched or handled this request.
Contexts known to this server are:
/ ---> o.e.j.w.WebAppContext@56ef9176{/,file:///var/lib/jetty/webapps/root/,UNAVAILABLE}{/root.war} [failed]

我有一个 build.gradle 和 pom.xml 文件,并且必须在两个文件中声明依赖项,我认为这是问题所在。

我的 pom.xml 包含:

<dependencyManagement>
  <dependencies>
    <dependency>
      <!-- Import dependency management from Spring Boot -->
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-dependencies</artifactId>
      <version>2.0.1.RELEASE</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
</dependencies>

我的 build.gradle 包含:

plugins {
  id 'org.springframework.boot' version '2.0.1.RELEASE'
}
apply plugin: 'io.spring.dependency-management'
dependencies {
  compile 'org.springframework.boot:spring-boot-starter-web'
}

当我从两者中删除两个 spring 引导依赖项时,错误消失。

有什么想法吗?

最后我自己弄明白了,但会留给其他遇到同样错误的人。
正如我在文档中发现的那样:如果您使用 WAR 作为可部署文件(而不是 .jar 文件),那么您还必须将 spring-boot-starter-tomcat 导入为提供的依赖项。

我的 pom.xml 现在看起来像:

<dependencyManagement>
  <dependencies>
    <dependency>
      <!-- Import dependency management from Spring Boot -->
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-dependencies</artifactId>
      <version>2.0.1.RELEASE</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
  </dependency>
</dependencies>

我的 build.gradle 现在看起来像:

plugins {
  id 'org.springframework.boot' version '2.0.1.RELEASE'
}
apply plugin: 'io.spring.dependency-management'
dependencies {
  compile 'org.springframework.boot:spring-boot-starter-web'
  providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
}