play scala 中的 ApplicationLifecycle 挂钩中的错误类型可调用

Wrong type of callable in ApplicationLifecycle hooks in play scala

我正在尝试在我们的应用程序 (Play Scala) 中注册服务停止挂钩。

基于这些文档,它非常简单。 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())
  }
}

但是,我遇到类型不匹配错误:

[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())

正确的做法是什么?

猜猜你使用 Java API play.inject.ApplicationLifecycle (which expects CompletionStage) and not the Scala one(它接受 Future)。