ich diesen einfachen Test Scala Anwendung haben, die eine blockierende HTTP-Anforderung:wie eine Scala Standalone-Anwendung, die die playframework Bibliotheken verwendet
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
}
}
Diese Anwendung schlägt fehl mit: Ausnahme im Thread "main" java.lang.RuntimeException: Es wurde keine Anwendung
gestartetWie löst man dieses Problem?
Das deutlichste Beispiel dafür, wie dies zu tun, das ich je gesehen habe Danke, Will. –
alles ist jetzt veraltet in 2.5.x. – ses
Hi @ses - bitte siehe https://www.playframework.com/documentation/2.5.x/ScalaWS#using-wsclient und https://www.playframework.com/documentation/2.5.x/ScalaTestingWebServiceClients –