简体   繁体   English

错误 R10(启动超时)-> Web 进程未能在启动后 60 秒内绑定到 $PORT - Heroku

[英]Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch - Heroku

I am trying to deploy my server on heroku.我正在尝试在 heroku 上部署我的服务器。 I got this error:我收到此错误:

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

This is my Java class:这是我的 Java 类:

package introsde.document.endpoint;
import javax.xml.ws.Endpoint;

import introsde.assignment.soap.PeopleImpl;

public class PeoplePublisher {
public static String SERVER_URL = "http://localhost";
public static String PORT = "6902";
public static String BASE_URL = "/ws/people";

public static String getEndpointURL() {
    return SERVER_URL+":"+PORT+BASE_URL;
}

public static void main(String[] args) {
    String endpointUrl = getEndpointURL();
    System.out.println("Starting People Service...");
    System.out.println("--> Published at = "+endpointUrl);
    Endpoint.publish(endpointUrl, new PeopleImpl());
}
}

How can I solve this problem?我怎么解决这个问题?

Thank you谢谢

I had the same issue trying to create a minimal spring-boot application.我在尝试创建一个最小的 spring-boot 应用程序时遇到了同样的问题。 I've compared heroku's java-getting-started implementation with mine and found this nice fix.我已经将 heroku 的 java-getting-started 实现与我的进行了比较,发现了这个很好的修复。 Just add this to src/main/resources/application.properties只需将此添加到src/main/resources/application.properties

server.port=${PORT:5000}

I had the same issue with port binding.我在端口绑定方面遇到了同样的问题。 Then I found this awesome article where I understood how actually everything works when deploying on Heroku.然后我发现了这篇很棒的文章,在那里我了解了在 Heroku 上部署时一切实际上是如何工作的。 After I read it I managed to solve my problem in 2 minutes.阅读后,我设法在 2 分钟内解决了我的问题。 The link has gone dead but find archived link here .该链接已失效,但可以在此处找到存档链接。

Simple solution:简单的解决方案:

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

Replace myapi-1.0.0 with the name of your jar or use *myapi-1.0.0替换为您的 jar 名称或使用*

Note: The order of the variables matter.注意:变量的顺序很重要。 For example: the following doesn't work.例如:以下不起作用。

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

You must bind to the port that Heroku assigns you as the env var $PORT , and the host 0.0.0.0 .您必须绑定到 Heroku 分配给您的端口作为 env var $PORT和主机0.0.0.0 So you should change you code to include this:因此,您应该更改代码以包含以下内容:

public static String PORT = System.getenv("PORT");

The SERVER_URL part may be trickier. SERVER_URL部分可能更棘手。 You could use 0.0.0.0, but if you truly need the publicly accessible URL, you'll need to set something like this (changing "yourappname" to your app name):您可以使用 0.0.0.0,但如果您确实需要可公开访问的 URL,则需要设置如下内容(将“yourappname”更改为您的应用程序名称):

$ heroku config:set SERVER_URL="https://yourappname.herokuapp.com"

And then add the code:然后添加代码:

public static String SERVER_URL = System.getenv("SERVER_URL");

Also, I would like to add that adding the following to Procfile, allowed me to deploy my Spring boot app to heroku and resolved the exception you described above:另外,我想添加以下内容到 Procfile,允许我将 Spring boot 应用程序部署到 heroku 并解决您上面描述的异常:

worker: java $JAVA_OPTS -jar target/myTargetJar-SNAPSHOT.jar

None of the solutions, listed on the web, helped me to solve the problem, this is why I decided to post the solution which helped me here.网上列出的所有解决方案都没有帮助我解决问题,这就是为什么我决定在这里发布对我有帮助的解决方案。 Maybe it is not on time, though :)不过可能不准时:)

Tried everything for myself.为自己尝试了一切。 Answer by @fortellao was a lifesaver for me. @fortellao 的回答对我来说是一个救星。 Just a little addition if someone is using src/main/resources/ application.yml like me:如果有人像我一样使用 src/main/resources/ application.yml,只需添加一点:

app:
  server:
    port: {$PORT}

port: 5000 did the trick in my case.端口: 5000 在我的情况下起到了作用。

Since your this is not a Spring Boot app you should do something like this:由于您的这不是 Spring Boot 应用程序,因此您应该执行以下操作:

package introsde.document.endpoint;
import javax.xml.ws.Endpoint;

import introsde.assignment.soap.PeopleImpl;

public class PeoplePublisher {
public static String SERVER_URL = "http://localhost";
public String port;
public static String BASE_URL = "/ws/people";

public static String getEndpointURL() {
    return SERVER_URL+":"+port+BASE_URL;
}

public static void main(String[] args) {

    port = Integer.valueOf(args[0]);

    String endpointUrl = getEndpointURL();
    System.out.println("Starting People Service...");
    System.out.println("--> Published at = "+endpointUrl);
    Endpoint.publish(endpointUrl, new PeopleImpl());
}
}

And then on your Procfile:然后在您的 Procfile 上:

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

This way you'll bind your socket to the port Heroku is expecting you to listen at.这样你就可以将你的套接字绑定到 Heroku 期望你监听的端口。

It's possible that you are making request without wait the server finish run, so it break because cannot finish building before 90 seconds.您可能在不等待服务器完成运行的情况下发出请求,因此它会中断,因为无法在 90 秒之前完成构建。

It's a guess that are happening here.这是这里发生的猜测。

This problem occurs when Heroku can not find the port specified in Procfile.当 Heroku 找不到 Procfile 中指定的端口时会出现此问题。

A simple solution to this problem is doing a port setting dynamically by Procfile.这个问题的一个简单解决方案是通过 Procfile 动态地进行端口设置。

Add in Procfile ->添加 Procfile ->

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

Remember that the Maven packaging should be JAR.请记住,Maven 打包应该是 JAR。

暂无
暂无

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

相关问题 Spring Docker 中的启动应用程序收到:错误 R10(启动超时)-> Web 进程在启动后 60 秒内无法绑定到 $PORT - Spring Boot app in Docker receives: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch 错误 R10(启动超时)-> 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) 错误 R10(启动超时)-> Web 进程未能在启动 java 的 90 秒内绑定到 $PORT - Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch java 错误 R10(启动超时)> Web 进程未能在启动后 90 秒内绑定到 $PORT - Error R10 (Boot timeout) > Web process failed to bind to $PORT within 90 seconds of launch Java Maven项目-错误R10(引导超时)-> Web进程在启动后90秒内未能绑定到$ PORT - Java Maven project - Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch Spring 托管在 Heroku 上的引导项目 - Web 进程未能在启动后 90 秒内绑定到 $PORT - Spring Boot project hosted on Heroku - 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 在Heroku上运行Dropwizard应用程序:R10无法绑定到$ PORT - Running Dropwizard app on Heroku: R10 failed to bind to $PORT 在Heroku上运行我的应用程序时,为什么会出现启动超时错误(错误R10)? - Why do I get a Boot timeout error (Error R10) when running my app on Heroku? 部署在 Heroku 上的 Quarkus 应用程序出现错误 R10(引导超时) - Quarkus application deployed on Heroku gives Error R10 (Boot Timeout)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM