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

后端 未结 8 592
情话喂你
情话喂你 2020-12-31 11:39

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

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


        
相关标签:
8条回答
  • 2020-12-31 12:12

    Since your this is not a Spring Boot app you should do something like this:

    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:

    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.

    0 讨论(0)
  • 2020-12-31 12:16

    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. After I read it I managed to solve my problem in 2 minutes. The link has gone dead but find archived link here.

    0 讨论(0)
  • 2020-12-31 12:21

    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

    server.port=${PORT:5000}
    
    0 讨论(0)
  • 2020-12-31 12:21

    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 *

    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
    
    0 讨论(0)
  • 2020-12-31 12:24

    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:

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

    0 讨论(0)
  • 2020-12-31 12:26

    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:

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

    The SERVER_URL part 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):

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

    And then add the code:

    public static String SERVER_URL = System.getenv("SERVER_URL");
    
    0 讨论(0)
提交回复
热议问题