用于 Spring Boot 项目的 buildspec.yml 文件

Posted

技术标签:

【中文标题】用于 Spring Boot 项目的 buildspec.yml 文件【英文标题】:buildspec.yml file for Spring Boot project 【发布时间】:2020-09-12 12:14:54 【问题描述】:

我有一个名为“BikeService”的 Spring Boot 项目。我正在使用 pom.xml 文件中的以下命令为这个项目生成一个 war 文件

<packaging>war</packaging>

现在我想将它部署在我使用

创建的 Elastic Beanstalk
Tomcat 8.5 with Java 8 running on 64bit Amazon Linux/3.3.6

上传代码后,部署成功,环境运行状况良好,但在运行环境 URL 时显示 HTTP 404 - Not Found

我正在使用以下 buildspec.yml 文件:

version: 0.2
phases:
  install:
    runtime-versions:
      java: corretto11
  pre_build:
    commands:
    - echo In the pre_build phase...
  build:
    commands:
    - echo Build started on `date`
    - mvn install
  post_build:
    commands:
    - echo Build completed on `date`
artifacts:
  files:
  - target/bike-service-0.0.1-SNAPSHOT.war
  - scripts/*

【问题讨论】:

当您登录您的 EB 实例并从内部curl 您的应用程序时,它是否在您想要的端口上按预期工作? 【参考方案1】:

所以经过大量研究,问题解决了。

问题在于 buildspec.yml 文件。

我将发布正确的 buildspec.yml 文件,以防将来有人搜索它。

以下文件如果用于 带有战争包装的 Spring Boot 项目

version: 0.2
phases:
  install:
    runtime-versions:
      java: corretto8
  pre_build:
    commands:
    - echo In the pre_build phase...
  build:
    commands:
    - echo Build started on `date`
  post_build:
    commands:
    - echo Build completed on `date`
    - mvn package
    - mv target/bike-service-0.0.1-SNAPSHOT.war bike-service-0.0.1-SNAPSHOT.war
artifacts:
  files:
  - bike-service-0.0.1-SNAPSHOT.war
  - .ebextensions/**/*

【讨论】:

以上是关于用于 Spring Boot 项目的 buildspec.yml 文件的主要内容,如果未能解决你的问题,请参考以下文章

在父 build.gradle 中找不到 ID 为 spring-boot 的插件

如何从 Gradle Multi Build 项目中发布 Spring Boot 应用程序?

如何在调试/运行 Spring Boot 项目的 IntelliJ“out”目录中生成 build-info.properties?

多模块 Spring Boot 项目中的 Gradle 依赖插件

Spring Boot gradle build - 无效的源版本:11

用spring tool suite插件创建spring boot项目时报An internal error occurred during: "Building UI model"