教程
Spring Boot

部署 Spring Boot 项目

这篇文章将会教你如何在 Zeabur 上部署你的 Spring Boot (opens in a new tab) 项目。

第一步:环境配置

你可以在本地测试构建,确保你的项目可以正常运行,可使用 JDK 版本为:

  • 19
  • 17(默认)
  • 11
  • 8
  • 7

指定 JDK 版本

你可以在 pom.xmlbuild.gradle 中指定 JDK 版本。

例如,如果你使用 Maven,请在 pom.xml 加入以下设置:

<properties>
    <java.version>11</java.version>
</properties>

如果你使用 Gradle,请在 build.gradle 加入以下设置:

sourceCompatibility = 11

第二步: 建立项目(可选)

首先,你需要在本地开发环境初始化一个 Spring Boot 项目,我们可以按照 Spring Boot 官方文件 (opens in a new tab) 的指示来完成这个步骤,或是依据你喜好的 IDE(例如 IntelliJ IDEA (opens in a new tab)Eclipse (opens in a new tab) 等等),初始化 Spring Boot 项目。

若使用 Gradle 部署工具,需在 Gradle 项目中打开 build.gradle 文件,加入以下配置:

jar {
    enabled = false
    manifest {
        attributes 'Main-Class': 'com.example.demo.DemoApplication' // <-- 请将此处的包名和类名替换为你的项目包名和类名
    }
}

创建完成后,为其初始化一个 Git 仓库并部署到你的 GitHub 上。

第三步:部署 Spring Boot 项目

在你的项目中,点击 Deploy service 或者 Add new service 按钮,选择 Deploy your source code.

deploy

搜索想要部署的 Spring Boot 代码仓库,点击导入,你的 Spring Boot 应用就将自动开始部署。