英文:
Spring Boot application deployed on Heroku still crashing
问题
我在Heroku上部署了我的Spring应用,但它每次都会崩溃。应用在本地主机上运行正常,并且在Heroku上似乎也能正常启动,但一分钟后就会崩溃。我甚至无法打开它,因为出现了超时错误。我附上了日志末尾的内容:
2020-04-09T15:29:42.942785+00:00 app[web.1]: 2020-04-09 15:29:42.942 INFO 4 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat在端口8080(http)上启动,上下文路径为''。
2020-04-09T15:29:42.945506+00:00 app[web.1]: 2020-04-09 15:29:42.945 INFO 4 --- [ main] c.a.a.backend.BackendApplication : 在15.604秒内启动了BackendApplication(JVM已运行17.531秒)。
2020-04-09T15:30:53.816851+00:00 heroku[web.1]: 状态从启动中更改为已崩溃
日志中没有更多的信息。我应该检查什么?
<details>
<summary>英文:</summary>
i deployed my Spring app on Heroku but it crashes every time. Application works fine on localhost and also seems to correctly starting on Heroku but after one minute it crashes. I can't even open it because i've got timeout. I attached end of the logs:
2020-04-09T15:29:42.942785+00:00 app[web.1]: 2020-04-09 15:29:42.942 INFO 4 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-04-09T15:29:42.945506+00:00 app[web.1]: 2020-04-09 15:29:42.945 INFO 4 --- [ main] c.a.a.backend.BackendApplication : Started BackendApplication in 15.604 seconds (JVM running for 17.531)
2020-04-09T15:30:53.816851+00:00 heroku[web.1]: State changed from starting to crashed
There is nothing more in logs. What can i check?
</details>
# 答案1
**得分**: 0
看起来你没有将你的Tomcat绑定到正确的端口。你需要绑定到Heroku提供的`$PORT`环境变量。Heroku有一篇关于这个的文章,也涵盖了Tomcat:https://devcenter.heroku.com/articles/setting-the-http-port-for-java-applications
<details>
<summary>英文:</summary>
It looks like you're not binding your tomcat to the correct port. You need to bind to the Heroku provided `$PORT` env variable. Heroku has an article about this, that also covers Tomcat: https://devcenter.heroku.com/articles/setting-the-http-port-for-java-applications
</details>
专注分享java语言的经验与见解,让所有开发者获益!
评论