Scala Play WS Standalone:实例化StandaloneAhcWSClient会导致一些wierd问题
我试图实现的目标非常直截了当:Scala Play WS Standalone:实例化StandaloneAhcWSClient会导致一些wierd问题,scala,playframework,asynchttpclient,Scala,Playframework,Asynchttpclient,我试图实现的目标非常直截了当: 按所述实例化独立实例 调用远程服务 但是,如果运行测试类,则会出现以下错误: java.lang.NoSuchMethodError:scala.Product.$init$(Lscala/Product;)V位于akka.util.Timeout 您将在下面找到完整的stacktrace 你知道是什么导致了这个问题,以及如何让这个例子起作用吗 package restclient import org.junit.runner.RunWith import o
package restclient
import org.junit.runner.RunWith
import org.scalatest._
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class RestClientTest extends WordSpecLike with ShouldMatchers {
trait Fixture {
val restClient = new RestClientImpl
}
"The Rest client" should {
"" in new Fixture {
val res = restClient.call("http://localhost:3000/post")
res shouldBe "c"
}
}
}
=============================================
package restclient
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import play.api.libs.ws.ahc._
// still WIP
trait RestClient {
def call(url: String): String
}
class RestClientImpl extends RestClient {
override def call(url: String): String = {
// Create Akka system for thread and streaming management
implicit val system = ActorSystem()
system.registerOnTermination {
System.exit(0)
}
implicit val m = ActorMaterializer()
val wsClient = StandaloneAhcWSClient()
"x"
}
}
<dependency>
<groupId>com.typesafe.play</groupId>
<artifactId>play-ahc-ws-standalone_2.12</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.typesafe.play</groupId>
<artifactId>play-ws-standalone-json_2.12</artifactId>
<version>1.0.7</version>
</dependency>
=============================================
package restclient
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import play.api.libs.ws.ahc._
// still WIP
trait RestClient {
def call(url: String): String
}
class RestClientImpl extends RestClient {
override def call(url: String): String = {
// Create Akka system for thread and streaming management
implicit val system = ActorSystem()
system.registerOnTermination {
System.exit(0)
}
implicit val m = ActorMaterializer()
val wsClient = StandaloneAhcWSClient()
"x"
}
}
<dependency>
<groupId>com.typesafe.play</groupId>
<artifactId>play-ahc-ws-standalone_2.12</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.typesafe.play</groupId>
<artifactId>play-ws-standalone-json_2.12</artifactId>
<version>1.0.7</version>
</dependency>
java.lang.NoSuchMethodError:scala.Product.$init$(Lscala/Product;)V
在akka.util.Timeout.(Timeout.scala:13)
在akka.actor.ActorSystem$设置中。(ActorSystem.scala:327)
在akka.actor.ActorSystemImpl.(ActorSystem.scala:650)
在akka.actor.ActorSystem$.apply上(ActorSystem.scala:244)
在akka.actor.ActorSystem$.apply(ActorSystem.scala:287)
在akka.actor.ActorSystem$.apply(ActorSystem.scala:232)
在akka.actor.ActorSystem$.apply(ActorSystem.scala:223)
在
restclient.restclientmpl.call(restclientmpl.scala:28)
在
restclient.RestClientTest$$anonfun$1$$anonfun$apply$mcV$sp$1$$anon$1。(RestClientTest.scala:16)
在restclient.RestClientTest$$anonfun$1$$anonfun$apply$mcV$sp$1.apply$mcV$sp(RestClientTest.scala:15)
在restclient.RestClientTest$$anonfun$1$$anonfun$apply$mcV$sp$1.apply(RestClientTest.scala:15)
在restclient.RestClientTest$$anonfun$1$$anonfun$apply$mcV$sp$1.apply(RestClientTest.scala:15)
在org.scalatest.Transformer$$anonfun$apply$1.apply$mcV$sp(Transformer.scala:22)
在org.scalatest.OutcomeOf$class.OutcomeOf(OutcomeOf.scala:85)
在org.scalatest.OutcomeOf$.OutcomeOf(OutcomeOf.scala:104)
在org.scalatest.Transformer.apply上(Transformer.scala:22)
在org.scalatest.Transformer.apply上(Transformer.scala:20)
在org.scalatest.WordSpecLike$$anon$1.apply上(WordSpecLike.scala:953)
位于org.scalatest.Suite$class.withFixture(Suite.scala:1122)
位于restclient.RestClientTest.withFixture(RestClientTest.scala:8)
在
=============================================
package restclient
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import play.api.libs.ws.ahc._
// still WIP
trait RestClient {
def call(url: String): String
}
class RestClientImpl extends RestClient {
override def call(url: String): String = {
// Create Akka system for thread and streaming management
implicit val system = ActorSystem()
system.registerOnTermination {
System.exit(0)
}
implicit val m = ActorMaterializer()
val wsClient = StandaloneAhcWSClient()
"x"
}
}
<dependency>
<groupId>com.typesafe.play</groupId>
<artifactId>play-ahc-ws-standalone_2.12</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>com.typesafe.play</groupId>
<artifactId>play-ws-standalone-json_2.12</artifactId>
<version>1.0.7</version>
</dependency>
com.typesafe.play
play-ahc-ws-standalone_2.12
1.0.7
com.typesafe.play
play-ws-standalone-json_2.12
1.0.7
您使用的是什么版本的Scala、Akka和ScalaTest?谢谢您的提示。该项目已经有一段时间没有更新了,仍然在使用Scala 2.11。但是升级起来是一件不合理的麻烦事,所以我打算试试http4s.org。为什么不使用_2.11呢?这很公平,但我在想,如果将来Scala 2.13应该再次与2.12 http4s决裂,迁移起来可能会更容易。你使用的是Scala、Akka和ScalaTest的哪些版本?谢谢你的提示。该项目已经有一段时间没有更新了,仍然在使用Scala 2.11。但是升级起来是一个不合理的麻烦,所以我打算试试http4s.org。为什么不在这种情况下使用_2.11呢?很公平,但我在想,如果将来Scala 2.13再次与2.12 http4s决裂,迁移起来可能会更容易一些。