Spring Boot应用部署Heroku遇R10启动超时错误求助
Hey there, let's get that R10 error sorted out—this is a super common gotcha when deploying Spring Boot apps to Heroku, so I’ve got you covered.
What’s causing this error?
Heroku requires all web processes to bind to the $PORT environment variable it provides when your app starts. By default, Spring Boot uses port 8080, which doesn’t match what Heroku expects. Since your app isn’t binding to the right port within 60 seconds, Heroku kills the process with that SIGTERM signal you see in the logs.
Step-by-step fixes:
Update your Spring Boot port configuration
Make your app read the$PORTvariable so it uses Heroku’s assigned port (and falls back to 8080 for local development):- If using
application.properties:server.port=${PORT:8080} - If using
application.yml:server: port: ${PORT:8080}
- If using
Verify your Procfile is set up correctly
Heroku uses the Procfile to know how to launch your app. Create or update a file namedProcfile(capital P, no file extension) in your project root with this line:web: java -jar target/your-app-filename.jarReplace
your-app-filename.jarwith the actual name of your built JAR file. If you’re using Maven, you can also useweb: mvn spring-boot:run, but the JAR approach is more reliable for production deployments.Re-deploy and check logs
Commit your changes to Git, then push to Heroku:git add . git commit -m "Fix Heroku port binding" git push heroku mainUse this command to tail the logs and confirm your app binds to the correct port:
heroku logs --tail
Bonus: If you still see timeouts
If your app takes longer than 60 seconds to start, Heroku will still trigger the R10 error. To fix this:
- Optimize your app’s startup time: use lazy initialization for non-critical beans, reduce unnecessary dependencies, or pre-load resources.
- Add JVM flags to speed up startup: update your Procfile to include flags like
XX:+UseParallelGC:web: java -XX:+UseParallelGC -jar target/your-app-filename.jar
内容的提问来源于stack exchange,提问作者Raghavulu

