简体   繁体   English

Spring 托管在 Heroku 上的引导项目 - Web 进程未能在启动后 90 秒内绑定到 $PORT

[英]Spring Boot project hosted on Heroku - Web process failed to bind to $PORT within 90 seconds of launch

I have read many similar questions on stackoverflow and nothing helped me.我在 stackoverflow 上阅读了许多类似的问题,但没有任何帮助。

I have created a spring boot maven backend project and hosted on heroku.我创建了一个 spring 启动 maven 后端项目并托管在 heroku 上。

But, when I try to call from the frontend, it shows an error like this in the browser.但是,当我尝试从前端调用时,它会在浏览器中显示这样的错误。 GET https://hoyamu-springboot-backend.herokuapp.com/fetch/bag 503

When I view the log of heroku it shows an error like this.当我查看 heroku 的日志时,它显示这样的错误。 Web process failed to bind to $PORT within 90 seconds of launch . Web process failed to bind to $PORT within 90 seconds of launch I did everything and nothing works.我做了一切,但没有任何效果。

My files are as below,我的文件如下,

Heroku Application Log Heroku 应用日志

020-08-08T21:32:21.232432+00:00 heroku[web.1]: State changed from crashed to starting
2020-08-08T21:32:25.103258+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=48348 $JAVA_OPTS -jar target/hoyamu-0.0.1-SNAPSHOT.jar`
2020-08-08T21:32:27.226023+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2020-08-08T21:32:27.230034+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8 
2020-08-08T21:32:28.818160+00:00 app[web.1]: 
2020-08-08T21:32:28.818210+00:00 app[web.1]:   .   ____          _            __ _ _
2020-08-08T21:32:28.818211+00:00 app[web.1]:  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
2020-08-08T21:32:28.818214+00:00 app[web.1]: ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
2020-08-08T21:32:28.818294+00:00 app[web.1]:  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
2020-08-08T21:32:28.818323+00:00 app[web.1]:   '  |____| .__|_| |_|_| |_\__, | / / / /
2020-08-08T21:32:28.818414+00:00 app[web.1]:  =========|_|==============|___/=/_/_/_/
2020-08-08T21:32:28.819695+00:00 app[web.1]:  :: Spring Boot ::        (v2.2.6.RELEASE)
2020-08-08T21:32:28.819727+00:00 app[web.1]: 
2020-08-08T21:32:29.047717+00:00 app[web.1]: 2020-08-08 21:32:29.044  INFO 4 --- [           main] com.udith.hoyamu.HoyamuApplication       : Starting HoyamuApplication v0.0.1-SNAPSHOT on 50382c68-eaab-4b3c-ac0c-a881a18e4a0b with PID 4 (/app/target/hoyamu-0.0.1-SNAPSHOT.jar started by u8138 in /app)
2020-08-08T21:32:29.048863+00:00 app[web.1]: 2020-08-08 21:32:29.048  INFO 4 --- [           main] com.udith.hoyamu.HoyamuApplication       : No active profile set, falling back to default profiles: default
2020-08-08T21:32:30.083462+00:00 app[web.1]: 2020-08-08 21:32:30.081  INFO 4 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-08-08T21:32:30.224960+00:00 app[web.1]: 2020-08-08 21:32:30.224  INFO 4 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 130ms. Found 18 JPA repository interfaces.
2020-08-08T21:32:31.310818+00:00 app[web.1]: 2020-08-08 21:32:31.310  INFO 4 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 48348 (http)
2020-08-08T21:32:31.327532+00:00 app[web.1]: 2020-08-08 21:32:31.327  INFO 4 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-08-08T21:32:31.327720+00:00 app[web.1]: 2020-08-08 21:32:31.327  INFO 4 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.33]
2020-08-08T21:32:31.405048+00:00 app[web.1]: 2020-08-08 21:32:31.404  INFO 4 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-08-08T21:32:31.405289+00:00 app[web.1]: 2020-08-08 21:32:31.405  INFO 4 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2272 ms
2020-08-08T21:32:31.669531+00:00 app[web.1]: 2020-08-08 21:32:31.669  INFO 4 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-08-08T21:32:31.931057+00:00 app[web.1]: 2020-08-08 21:32:31.930  INFO 4 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.12.Final
2020-08-08T21:32:32.109028+00:00 app[web.1]: 2020-08-08 21:32:32.108  INFO 4 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-08-08T21:32:32.249430+00:00 app[web.1]: 2020-08-08 21:32:32.249  INFO 4 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2020-08-08T21:32:33.786599+00:00 app[web.1]: 2020-08-08 21:32:33.786  INFO 4 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2020-08-08T21:32:33.850851+00:00 app[web.1]: 2020-08-08 21:32:33.850  INFO 4 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2020-08-08T21:33:55.347291+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
2020-08-08T21:33:55.368253+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-08-08T21:33:55.465503+00:00 heroku[web.1]: Process exited with status 137
2020-08-08T21:33:55.499546+00:00 heroku[web.1]: State changed from starting to crashed

2020-08-08T21:50:58.187914+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/fetch/bag" host=hoyamu-springboot-backend.herokuapp.com request_id=db721f39-aab3-4a3f-82e9-6495dc6bc7a8 fwd="112.135.40.125" dyno= connect= service= status=503 bytes= protocol=https

Procfile档案

web: java -Dserver.port=$PORT $JAVA_OPTS -jar target/hoyamu-0.0.1-SNAPSHOT.jar

application.properties应用程序属性

hibernate.dialect=org.hibernate.dialect.MySQL57Dialect

spring.datasource.url=jdbc:mysql://remotemysql.com:3306/MMgqawaw
spring.datasource.username=username
spring.datasource.password=password

spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.show_sql=true
spring.jpa.hibernate.format_sql=true
spring.jpa.show-sql=true


```
What should I do?

After several small surveys, I could find the solution for my issue.经过几次小型调查,我可以找到解决问题的方法。

The error Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch can happen due to two reasons.错误Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch可能由于两个原因而发生。

  1. Actually the app cannot bind the port as it is not defined in the procfile properly.实际上应用程序无法绑定端口,因为它没有在 procfile 中正确定义。 You can find solutions for that by reading some stackoverflow questions.您可以通过阅读一些 stackoverflow 问题找到解决方案。 In brief, procfile should look like this:简而言之,procfile 应该如下所示:

(replace <BUILT_APP_NAME_HERE> with your app name after deployed) (部署后将 <BUILT_APP_NAME_HERE> 替换为您的应用名称)

web: java $JAVA_OPTS -jar -Dserver.port=$PORT target/<BUILT_APP_NAME_HERE>.jar

[or] [或者]

When giving *, you don't need to specify the name给*的时候不需要指定名字

web: java $JAVA_OPTS -jar -Dserver.port=$PORT target/*.jar

[or] [或者]

web: java $JAVA_OPTS -jar -Dspring.profiles.active=production target/<BUILT_APP_NAME_HERE>.jar --port $PORT

  1. Second reason is, as shown in the error, it tries to bind the port after 90 seconds (for some apps it is 60 secs) of launch, even though the app has not yet fully started.第二个原因是,如错误所示,它尝试在启动 90 秒(对于某些应用程序为 60 秒)后绑定端口,即使应用程序尚未完全启动。 By default, for java apps,heroku has set a limit of 90 secs as the boot time.默认情况下,对于 java 应用程序,heroku 已将启动时间限制为 90 秒。 If Heroku cannot bind the port during that time, the app is marked as crashed.如果 Heroku 在此期间无法绑定端口,则应用程序被标记为崩溃。 Here, in my project, it takes another little time for making the connection with remote database, but heroku doesn't wait till the db connection is made as its boot time is 90 secs.在这里,在我的项目中,与远程数据库建立连接需要一点时间,但是 heroku 不会等到建立数据库连接,因为它的启动时间是 90 秒。

The solution for this is, we have to increase the boot time of the app.解决方案是,我们必须增加应用程序的启动时间。 you can do this by following this link.您可以按照此链接执行此操作。 ( Sometimes this link gives errors, then try with another browser or with your mobile phone's browser) (这个链接有时候会报错,换个浏览器或者手机浏览器试试)

https://tools.heroku.support/limits/boot_timeout https://tools.heroku.support/limits/boot_timeout

However, it is not recommended to increase the boot time more 120secs.但是,不建议将启动时间增加 120 秒以上。

But, in real case, you should find the solution why it takes much time to make the db connection.但是,在实际情况下,您应该找到为什么需要花费大量时间来建立数据库连接的解决方案。

i was able to run my spring mvc app with this Procfile content:我能够使用此 Procfile 内容运行我的 spring mvc 应用程序:

web: java $JAVA_OPTS -jar target/dependency/webapp-runner.jar --port $PORT target/*.war web: java $JAVA_OPTS -jar 目标/依赖/webapp-runner.jar --port $PORT 目标/*.war

this is the deployed app: http://duckingrace.herokuapp.com/web/canvasv1这是部署的应用程序: http://duckingrace.herokuapp.com/web/canvasv1

this is the source code: https://github.com/fajaralmu/java-websocket1这是源代码: https://github.com/fajaralmu/java-websocket1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误 R10(启动超时)-&gt; Web 进程未能在启动后 90 秒内绑定到 $PORT(Heroku 上的 Java Discord 机器人) - Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch (Java Discord bot on Heroku) Java Maven项目-错误R10(引导超时)-&gt; Web进程在启动后90秒内未能绑定到$ PORT - Java Maven project - Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch Heroku-Web 进程未能在启动后 90 秒内绑定到 $PORT。 TooTallNate Websockets - Heroku- Web process failed to bind to $PORT within 90 seconds of launch. TooTallNate Websockets 错误 R10(启动超时)&gt; Web 进程未能在启动后 90 秒内绑定到 $PORT - Error R10 (Boot timeout) > Web process failed to bind to $PORT within 90 seconds of launch 错误 R10(启动超时)-&gt; Web 进程未能在启动 java 的 90 秒内绑定到 $PORT - Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch java 错误 R10(启动超时)-&gt; Web 进程未能在启动后 60 秒内绑定到 $PORT - Heroku - Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch - Heroku 上传失败 spring 启动到 heroku - Failed to upload spring boot to heroku 无法将Spring Boot应用程序启动到Linux服务器中 - Failed to launch Spring boot application into Linux server Spring Heroku 中的引导项目作为对另一个本地 Spring 引导项目的依赖项? - Spring boot project in Heroku as dependency to another local Spring Boot project? Web 服务器启动失败。 端口 8080 已被使用。 Spring 启动微服务 - Web server failed to start. Port 8080 was already in use. Spring Boot microservice
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM