[英]Wrong type of callable in ApplicationLifecycle hooks in play scala
I am trying to register a stop hook on service in our application (Play Scala).我正在尝试在我们的应用程序(Play Scala)中注册服务的停止挂钩。
Based on these docs it's pretty straightforward.基于这些文档,它非常简单。 https://www.playframework.com/documentation/2.8.x/PluginsToModules#Create-a-Module-class And should be something like this:
https://www.playframework.com/documentation/2.8.x/PluginsToModules#Create-a-Module-class应该是这样的:
@Singleton
class AblyService @Inject() (ablyRealtime: AblyRealtime, lifecycle: ApplicationLifecycle) {
def getChannel(name: String): Channel = ablyRealtime.channels.get(name)
lifecycle.addStopHook { () =>
Future.successful(ablyRealtime.close())
}
}
However, I am getting a type missmatch error:但是,我收到类型不匹配错误:
[error] /Users/shurikag/ProcessStreet/dev/process-street/app/features/ably/AblyService.scala:15:22: type mismatch;
[error] found : scala.concurrent.Future[Unit]
[error] required: java.util.concurrent.CompletionStage[_]
[error] Future.successful(ablyRealtime.close())
What is the correct way to do it?正确的方法是什么?
Guess you use the Java API play.inject.ApplicationLifecycle
(which expects CompletionStage
) and not the Scala one (which accepts a Future
).猜你使用 Java API
play.inject.ApplicationLifecycle
(期望CompletionStage
)而不是Scala 一个(接受Future
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.