![](/img/trans.png)
[英]Spring Boot app in Docker receives: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
[英]Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch - Heroku
我正在嘗試在 heroku 上部署我的服務器。 我收到此錯誤:
Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
這是我的 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());
}
}
我怎么解決這個問題?
謝謝
我在嘗試創建一個最小的 spring-boot 應用程序時遇到了同樣的問題。 我已經將 heroku 的 java-getting-started 實現與我的進行了比較,發現了這個很好的修復。 只需將此添加到src/main/resources/application.properties
server.port=${PORT:5000}
簡單的解決方案:
web: java -Dserver.port=$PORT $JAVA_OPTS -jar target/myapi-1.0.0.jar
將myapi-1.0.0
替換為您的 jar 名稱或使用*
注意:變量的順序很重要。 例如:以下不起作用。
web: java $JAVA_OPTS -Dserver.port=$PORT -jar target/myapi-1.0.0.jar
您必須綁定到 Heroku 分配給您的端口作為 env var $PORT
和主機0.0.0.0
。 因此,您應該更改代碼以包含以下內容:
public static String PORT = System.getenv("PORT");
SERVER_URL
部分可能更棘手。 您可以使用 0.0.0.0,但如果您確實需要可公開訪問的 URL,則需要設置如下內容(將“yourappname”更改為您的應用程序名稱):
$ heroku config:set SERVER_URL="https://yourappname.herokuapp.com"
然后添加代碼:
public static String SERVER_URL = System.getenv("SERVER_URL");
另外,我想添加以下內容到 Procfile,允許我將 Spring boot 應用程序部署到 heroku 並解決您上面描述的異常:
worker: java $JAVA_OPTS -jar target/myTargetJar-SNAPSHOT.jar
網上列出的所有解決方案都沒有幫助我解決問題,這就是為什么我決定在這里發布對我有幫助的解決方案。 不過可能不准時:)
為自己嘗試了一切。 @fortellao 的回答對我來說是一個救星。 如果有人像我一樣使用 src/main/resources/ application.yml,只需添加一點:
app:
server:
port: {$PORT}
端口: 5000 在我的情況下起到了作用。
由於您的這不是 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());
}
}
然后在您的 Procfile 上:
web: java $JAVA_OPTS -jar target/*.jar $PORT
這樣你就可以將你的套接字綁定到 Heroku 期望你監聽的端口。
您可能在不等待服務器完成運行的情況下發出請求,因此它會中斷,因為無法在 90 秒之前完成構建。
這是這里發生的猜測。
當 Heroku 找不到 Procfile 中指定的端口時會出現此問題。
這個問題的一個簡單解決方案是通過 Procfile 動態地進行端口設置。
添加 Procfile ->
web: java -Dserver.port=$PORT $JAVA_OPTS -jar target/nome_do_meu_app.jar
請記住,Maven 打包應該是 JAR。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.