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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34066878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 22:26:17  来源:igfitidea点击:

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

javaherokusoap

提问by Joe

I am trying to deploy my server on heroku. I got this error:

我正在尝试在 heroku 上部署我的服务器。我收到此错误:

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

谢谢

回答by fortellao

I had the same issue trying to create a minimal spring-boot application. I've compared heroku's java-getting-started implementation with mine and found this nice fix. Just add this to src/main/resources/application.properties

我在尝试创建一个最小的 spring-boot 应用程序时遇到了同样的问题。我已经将 heroku 的 java-getting-started 实现与我的进行了比较,发现了这个很好的修复。只需将此添加到src/main/resources/application.properties

server.port=${PORT:5000}

回答by Stefan Razvan Florea

I had the same issue with port binding. Then I found thisawesome article where I understood how actually everything works when deploying on Heroku. After I read it I managed to solve my problem in 2 minutes. The link has gone dead but find archived link here.

我在端口绑定方面遇到了同样的问题。然后我找到了这篇很棒的文章,在那里我了解了在 Heroku 上部署时一切实际上是如何工作的。阅读后,我设法在 2 分钟内解决了我的问题。该链接已失效,但可以在此处找到存档链接。

回答by biniam

Simple solution:

简单的解决方案:

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

Replace myapi-1.0.0with 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

回答by codefinger

You must bind to the port that Heroku assigns you as the env var $PORT, and the host 0.0.0.0. So you should change you code to include this:

您必须绑定到 Heroku 分配给您的端口作为 env var$PORT和主机0.0.0.0。因此,您应该更改代码以包含以下内容:

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

The SERVER_URLpart may be trickier. 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):

SERVER_URL部分可能更棘手。您可以使用 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");

回答by Daniil Zaru

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

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 :)

网上列出的所有解决方案都没有帮助我解决问题,这就是为什么我决定在这里发布对我有帮助的解决方案。不过可能不准时:)

回答by Luana FN

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 期望你监听的端口。

回答by Sham Fiorin

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.

这是这里发生的猜测。

回答by Phill Monteiro

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

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

Remember that the Maven packaging should be JAR.

请记住,Maven 打包应该是 JAR。