Heroku部署Spring Boot Gradle应用后启动崩溃,API请求返回503 Service Unavailable求助
Let's break down your issue and fix it step by step:
Root Cause
The error no main manifest attribute, in build/libs/LawCase-0.0.1-SNAPSHOT-plain.jar tells us exactly what's wrong: you're trying to run the plain JAR generated by Gradle's standard jar task. This JAR doesn't include Spring Boot's bootstrap logic or metadata pointing to your main application class. Spring Boot apps require the executable JAR created by the bootJar task (the one without the -plain suffix).
Step 1: Fix Your Procfile
Update your Procfile to target the correct executable JAR (remove the -plain suffix):
web: java -jar build/libs/LawCase-0.0.1-SNAPSHOT.jar
Step 2: Verify the Executable JAR Locally (Optional but Recommended)
Before redeploying, test the JAR on your local machine to confirm it works as expected:
java -jar build/libs/LawCase-0.0.1-SNAPSHOT.jar
If it starts up successfully and you can access your API locally, you're ready to redeploy.
Step 3: Redeploy to Heroku
Commit your Procfile change and push to Heroku:
git add Procfile git commit -m "Fix Procfile to use Spring Boot executable JAR" git push heroku main
Step 4: Validate the Deployment
After deployment, check the Heroku logs to confirm no startup errors:
heroku logs --tail
You should see Spring Boot's familiar startup logs instead of the manifest error. Once the app shows a "running" state, test your API endpoint https://lawcase.herokuapp.com/getprofiles again.
Additional Checks (If Issues Persist)
- Confirm your
build.gradlehas the Spring Boot plugin correctly applied (this ensures thebootJartask is enabled):plugins { id 'org.springframework.boot' version 'your-spring-boot-version' id 'io.spring.dependency-management' version 'your-dependency-management-version' id 'java' } - Double-check that your main application class has the
@SpringBootApplicationannotation and a validmainmethod:@SpringBootApplication public class LawCaseApplication { public static void main(String[] args) { SpringApplication.run(LawCaseApplication.class, args); } }
内容的提问来源于stack exchange,提问作者Ahmad

