问题
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
This is my Java class:
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
回答1:
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}
回答2:
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.
回答3:
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
回答4:
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");
回答5:
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 :)
回答6:
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.
回答7:
It's possible that you are making request without wait the server finish run, so it break because cannot finish building before 90 seconds.
It's a guess that are happening here.
回答8:
This problem occurs when Heroku can not find the port specified in Procfile.
A simple solution to this problem is doing a port setting dynamically by Procfile.
Add in Procfile ->
web: java -Dserver.port=$PORT $JAVA_OPTS -jar target/nome_do_meu_app.jar
Remember that the Maven packaging should be JAR.
来源:https://stackoverflow.com/questions/34066878/error-r10-boot-timeout-web-process-failed-to-bind-to-port-within-60-second