You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Heroku部署Spring Boot应用构建成功但访问返回503服务不可用错误

问题原因

从日志中可以明确看到报错no main manifest attribute, in target/XXX.jar,根本原因是你的pom.xml中缺少Spring Boot专用的打包插件:

  1. 你当前仅配置了maven编译插件,打包生成的是普通jar包,jar包的MANIFEST.MF文件中没有指定启动主类的配置,Heroku启动应用时找不到入口直接崩溃,触发H10错误返回503状态码。
  2. 没有配置Procfile的情况下Heroku会使用默认启动命令,但若jar包名不匹配也会导致启动失败。

解决方案

  1. 修改pom.xml添加spring-boot-maven-plugin
    在<build><plugins>节点下新增如下插件配置,原有maven-compiler-plugin配置保留即可:
<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <!-- 替换为你项目中启动类的全限定名 -->
        <mainClass>com.sample.app.SampleAppApplication</mainClass>
        <excludes>
            <exclude>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
            </exclude>
        </excludes>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

该插件会将项目打包为可执行jar,自动在MANIFEST.MF中添加主类配置。

  1. 添加Procfile(可选,推荐配置)
    在项目根目录新建名为Procfile的无后缀文件,写入内容:
web: java -Dserver.port=$PORT $JAVA_OPTS -jar target/sample-app-0.0.1-SNAPSHOT.jar

注意jar包名要和你pom中定义的artifactId、版本号对应,避免路径错误。

  1. 重新部署
    将修改后的代码提交到Heroku,重新触发构建部署即可解决问题。

内容的提问来源于stack exchange,提问作者Vaibs007

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 06:18:02