【问题标题】:Spring Boot causes WebAppContext error when deployed to GAESpring Boot 部署到 GAE 时导致 WebAppContext 错误
【发布时间】:2018-04-28 19:03:33
【问题描述】:

我正在为个人项目构建一个 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 boot 依赖项时,错误消失了。

有什么想法吗?

【问题讨论】:

    标签: spring google-app-engine spring-boot spring-boot-maven-plugin spring-boot-gradle-plugin


    【解决方案1】:

    最后我自己想通了,但会留给其他偶然发现相同错误的人。
    正如我在文档中发现的那样:如果您使用 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'
    }
    

    【讨论】:

      猜你喜欢
      • 2017-04-12
      • 2014-10-13
      • 2021-09-28
      • 2011-05-01
      • 2015-02-06
      • 1970-01-01
      • 2018-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多