我有一个注入了WSClient依赖的类:
@Singleton
class MyApiService @Inject() (wsclient: WSClient, conf: Configuration) {
...
}
当使用注入器运行测试并创建MyApiService实例时:
class MyTest extends FreeSpec with OneAppPerSuite with ScalaFutures with WsScalaTestClient {
implicit lazy val materializer: Materializer = app.materializer
lazy val wsc: WSClient = app.injector.instanceOf[WSClient]
lazy val conf: Configuration = app.injector.instanceOf[Configuration]
val myApiService: MyApiService = app.injector.instanceOf[MyApiService]
"Api Test" in {
...
}
我收到此错误:
An exception or error caused a run to abort: Unable to provision, see
the following errors:1) Error injecting constructor, java.lang.NumberFormatException:
format error 10000 at
play.api.libs.ws.ahc.AsyncHttpClientProvider.(AhcWSModule.scala:40)
at
play.api.libs.ws.ahc.AsyncHttpClientProvider.class(AhcWSModule.scala:39)
while locating play.api.libs.ws.ahc.AsyncHttpClientProvider while
locating play.shaded.ahc.org. … Caused by:
java.lang.NumberFormatException: format error 10000在我的申请中,我补充说:
ws.timeout.connection = 10000 ws.timeout.idle = 10000 ws.timeout.request = 10000
试图改为60000 theres没有区别……
使用play 2.6.0和scala 2.11.8
有人可能知道为什么会失败?
谢谢
解决方法:
我遇到了同样的问题.这是ws.timeout属性的格式问题.
在Play 2.6中,这些属性需要具有时间单位.这是一个example configuration
WSConfigParser尝试使用这些属性中的值构造scala.concurrent.Duration的实例.如果提供的值没有有效的时间单位,则持续时间为throw an exception.
修复是将ms添加到这些属性 – > 1000毫秒
这是我的application.conf
play {
ws {
timeout {
connection: 10000ms
idle: 30000ms
request: 60000ms
}
}
}
原文地址:https://codeday.me/bug/20190701/1349578.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。