我有一个api服务类,它依赖于play的配置和WSClient实例。
我不想使用@Inject()指定,因为我想在Macwire中使用编译时注入,所以我所做的是:
// this is a trait that here im wiring all the dependencies that my api service needs
trait ApiDependencies {
lazy val conf: Configuration = wire[Configuration]
lazy val wsc: WSClient = wire[WSClient]
}
// this
我对Play 2.7 documentation中的这个例子不太理解。 class ExampleSpec extends PlaySpec with GuiceOneServerPerSuite {
// Override app if you need an Application with other than
// default parameters.
override def fakeApplication(): Application = {
GuiceApplicationBuilder()
.appRoutes(app => {
在play 2.6中,网址(WSClient.url)编码如下:这里的%25被添加到我的网址中。
I am using javaWS in build.sbt
import play.libs.ws.*;
@Inject WSClient ws;
WSRequest wsReq = ws.url(getUrl());
当我使用play 2.5,代码是WS.url(url)时,这不是问题。你能帮我解决这个问题吗。
谢谢
我有一个代码示例,如下所示,其中我使用WSClient进行API调用。我使用的是2.5.x和Scala 2.11.11 (使用Play提供的WSClient,而不是独立的)。在异常情况下,我需要将WSResponse对象返回给此方法的调用者。在文档中,我找到了一个提供AhcWSResponse的Ahc包。您知道如何创建WSResponse对象吗?我尝试基于一个链接,如下所示,但这不起作用。 How to create a WSResponse object from string for Play WSClient def fetchData (request: WSRequest): Fu
我使用Play的AhcWSClient来发出HTTP请求(我不使用Play框架的其余部分):
implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()
val wsClient = AhcWSClient()
wsClient
.url(s"http://somerandomurl.com/somethingsomething")
.get()
.map { wsResponse =>
if (!(200 to 299).contains(ws
我想在我的一个测试类中注入配置实例,我用ConfiguredApp扩展了我的测试类,并注入了配置,如下所示:
@DoNotDiscover()
class MyApiServiceSpec extends FreeSpec with ScalaFutures with ConfiguredApp {
implicit val formats = DefaultFormats
implicit val exec = global
lazy val configuration = app.injector.instanceOf[Configuration]
"Glo