1

部署到 Heroku 后,Spark 服务器崩溃并出现此异常。我的 Procfile 看起来像这样:

web: java $JAVA_OPTS -Dserver=$PORT -jar target/myappname-0.0.1-SNAPSHOT.jar

据我了解,每次部署应用程序时 Heroku 都会分配一个新的端口。但是,我从 Heroku 设置的环境变量中获取了 PORT 值,为什么我无法获取这个请求的地址?

编辑:这些是我将 Procfile 更正为 -Dserver.port=$PORT 后的错误日志。

2015-11-21T16:45:02.832568+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx384m -Xss512k -Dfile.encoding=UTF-8
2015-11-21T16:45:04.061714+00:00 app[web.1]: [Thread-1] ERROR spark.webserver.JettySparkServer - ignite failed
2015-11-21T16:45:03.918669+00:00 app[web.1]: [Thread-1] INFO org.eclipse.jetty.util.log - Logging initialized @1084ms
2015-11-21T16:45:03.989340+00:00 app[web.1]: [Thread-1] INFO spark.webserver.JettySparkServer - == Spark has ignited ...
2015-11-21T16:45:03.989452+00:00 app[web.1]: [Thread-1] INFO spark.webserver.JettySparkServer - >> Listening on myappname.herokuapp.com:27925
2015-11-21T16:45:03.998409+00:00 app[web.1]: [Thread-1] INFO org.eclipse.jetty.server.Server - jetty-9.3.z-SNAPSHOT
2015-11-21T16:45:04.062462+00:00 app[web.1]: java.net.BindException: Cannot assign requested address
2015-11-21T16:45:04.062702+00:00 app[web.1]:    at sun.nio.ch.Net.bind0(Native Method)
2015-11-21T16:45:04.065229+00:00 app[web.1]:    at sun.nio.ch.Net.bind(Net.java:433)
2015-11-21T16:45:04.065305+00:00 app[web.1]:    at sun.nio.ch.Net.bind(Net.java:425)
2015-11-21T16:45:04.065472+00:00 app[web.1]:    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
2015-11-21T16:45:04.065412+00:00 app[web.1]:    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
2015-11-21T16:45:04.065575+00:00 app[web.1]:    at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:326)
2015-11-21T16:45:04.065628+00:00 app[web.1]:    at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
2015-11-21T16:45:04.065688+00:00 app[web.1]:    at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:244)
2015-11-21T16:45:04.065758+00:00 app[web.1]:    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
2015-11-21T16:45:04.067368+00:00 app[web.1]:    at org.eclipse.jetty.server.Server.doStart(Server.java:384)
2015-11-21T16:45:04.067370+00:00 app[web.1]:    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
2015-11-21T16:45:04.067370+00:00 app[web.1]:    at spark.webserver.JettySparkServer.ignite(JettySparkServer.java:131)
2015-11-21T16:45:04.067371+00:00 app[web.1]:    at spark.SparkInstance.lambda$init$0(SparkInstance.java:341)
2015-11-21T16:45:04.067372+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:745)
2015-11-21T16:45:05.052415+00:00 heroku[web.1]: State changed from starting to crashed
2015-11-21T16:45:05.036728+00:00 heroku[web.1]: Process exited with status 100

这发生在添加 --port $PORT 之后。基本上,我认为错误没有变化。

2015-11-21T17:51:14.666062+00:00 app[web.1]: [Thread-0] INFO org.eclipse.jetty.util.log - Logging initialized @230ms
2015-11-21T17:51:14.779260+00:00 app[web.1]: java.net.BindException: Cannot assign requested address
2015-11-21T17:51:14.779449+00:00 app[web.1]:    at sun.nio.ch.Net.bind0(Native Method)
2015-11-21T17:51:14.721317+00:00 app[web.1]: [Thread-0] INFO spark.webserver.JettySparkServer - == Spark has ignited ...
2015-11-21T17:51:14.779526+00:00 app[web.1]:    at sun.nio.ch.Net.bind(Net.java:433)
2015-11-21T17:51:14.779573+00:00 app[web.1]:    at sun.nio.ch.Net.bind(Net.java:425)
2015-11-21T17:51:14.721319+00:00 app[web.1]: [Thread-0] INFO spark.webserver.JettySparkServer - >> Listening on myappname.herokuapp.com:29822
2015-11-21T17:51:14.779601+00:00 app[web.1]:    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
2015-11-21T17:51:14.779661+00:00 app[web.1]:    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
2015-11-21T17:51:14.721320+00:00 app[web.1]: [Thread-0] INFO org.eclipse.jetty.server.Server - jetty-9.3.z-SNAPSHOT
2015-11-21T17:51:14.779796+00:00 app[web.1]:    at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
2015-11-21T17:51:14.779732+00:00 app[web.1]:    at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:326)
2015-11-21T17:51:14.778639+00:00 app[web.1]: [Thread-0] ERROR spark.webserver.JettySparkServer - ignite failed
2015-11-21T17:51:14.779884+00:00 app[web.1]:    at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:244)
2015-11-21T17:51:14.779949+00:00 app[web.1]:    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
2015-11-21T17:51:14.779980+00:00 app[web.1]:    at org.eclipse.jetty.server.Server.doStart(Server.java:384)
2015-11-21T17:51:14.780034+00:00 app[web.1]:    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
2015-11-21T17:51:14.780071+00:00 app[web.1]:    at spark.webserver.JettySparkServer.ignite(JettySparkServer.java:131)
2015-11-21T17:51:14.780110+00:00 app[web.1]:    at spark.SparkInstance.lambda$init$0(SparkInstance.java:341)
2015-11-21T17:51:14.780153+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:745)
2015-11-21T17:51:15.393560+00:00 heroku[web.1]: Process exited with status 100
2015-11-21T17:51:15.399506+00:00 heroku[web.1]: State changed from starting to crashed
4

2 回答 2

2

我发现问题是我在我的主要方法中设置了域的 IP 地址。看来我们不应该设置它,而只能通过从环境变量 $PORT 中获取它来设置 PORT。

于 2015-11-21T18:21:47.720 回答
0

-Dserver.port=$PORT在 Procfile 中使用而不是-Dserver=$PORT部署应用程序。如果错误仍然存​​在,请在日志中发布您收到的确切错误。

于 2015-11-21T08:05:03.620 回答