【发布时间】:2014-11-30 23:00:02
【问题描述】:
我有这个简单的测试 Scala 应用程序,它阻塞了 http 请求:
build.sbt
name := "hello"
version := "1.0"
scalaVersion := "2.11.2"
libraryDependencies += "com.typesafe.play" %% "play-ws" % "2.4.0-M1"
Test.scala
import play.api.libs.json._
import play.api.libs.ws._
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}
object Test {
def main(args: Array[String]) = {
val wsClient = WS.client
val body = getBody(wsClient.url("http://example.com/").get())
println(s"body: $body")
}
def getBody(future: Future[WSResponse]) = {
val response = Await.result(future, Duration.Inf);
if (response.status != 200)
throw new Exception(response.statusText);
response.body
}
}
此应用程序失败:
Exception in thread "main" java.lang.RuntimeException: There is no started application
如何解决这个问题?
【问题讨论】: