gpt4 book ai didi

Scala Play 测试在依赖注入(inject)期间找不到 WSClient

转载 作者:行者123 更新时间:2023-11-28 21:09:25 26 4
gpt4 key购买 nike

我正在尝试使用以下方法将一个类 DI 到单元测试中:

val injector = new GuiceInjectorBuilder().injector()
val secured = injector.instanceOf[Secured]

但是当我尝试运行它时,出现以下错误:

[info] Exception encountered when attempting to run a suite with class name: org.scalatest.DeferredAbortedSuite *** ABORTED ***
[info] com.google.inject.ConfigurationException: Guice configuration errors:
[info]
[info] 1) No implementation for play.api.libs.ws.WSClient was bound.
[info] while locating play.api.libs.ws.WSClient
[info] for parameter 3 at com.fredley.Secured.<init>(Secured.scala:36)
[info] while locating com.fredley.Secured

...

我做错了什么?

最佳答案

问题不是从应用程序构建注入(inject)器(意味着未加载 Play 依赖项)。这解决了问题:

val application = new GuiceApplicationBuilder().build
val secured = application.injector.instanceOf[Secured]

关于Scala Play 测试在依赖注入(inject)期间找不到 WSClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39226420/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com