Play Framework 2.6.20 PlayService插件项目应用程序生命周期支持



我正在试用Play 2.6引入的新PlayService sbt插件(我的确切Play版本是2.6.20(,我想在这个基于PlayService插件的Play项目中使用下面链接中提到的应用程序的停止挂钩。

https://www.playframework.com/documentation/2.6.x/JavaDependencyInjection#Stopping/cleaning-上行

我的代码如下,

@Singleton
public class LtrBootStrapper {
@Inject
public LtrBootStrapper(ApplicationLifecycle applicationLifecycle) {
//Other functionalities
//Actual components to stop inside stop hook to be added later on
applicationLifecycle.addStopHook(() -> CompletableFuture.completedFuture(null));
} 
}

但是,当我启动应用程序时,它无法启动,出现以下异常。

1个错误]play.core.server.DevServerStart$$anon$1.reload(DevServerStart.scala:186(在play.core.server.DevServerStart$$anon$1.get(DevServerStart.scala:124(在play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:241(在play.core.server.AkkaHttpServer.$anonfun$createServerBinding$1(AkkaHttpServer.scala:138(在akka.stream.impl.fusing.MapAsyncUnordered$$anon$26.onPush(Ops.scala:1304(在akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInteroper.scala:519(在akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInteroper.scala:482(在akka.stream.impl.fusing.GraphInterpreter.execute(GraphInteroper.scala:378(在akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:588(在akka.stream.impl.fusing.GraphInterpreterShell$AsyncInput.execute(ActorGraphInteroper.scala:472(原因:com.google.inject.CreateException:无法创建注射器,请参阅以下错误:

1(没有play.inject.ApplicationLifecycle的实现已绑定
查找play.inject.ApplicationLifecycle时用于com.mycompany.ltr.startup.LtrBootStrapper.(LtrBootStraper.java:22(的第一个参数

这是否意味着PlayService应用程序不支持ApplicationLifecycle?如果是,在PlayService应用程序中,停止挂钩等效的替代方案是什么?

提前谢谢。

ApplicationLifecycleplay.inject.BuiltInModule提供。这是由java核心子项目提供的,PlayMinimalJava(和PlayJava(会自动添加依赖项,但PlayService不会。

要解决此问题,请显式地将依赖项添加到build.sbt中,如下所示:

libraryDependencies += javaCore

相关内容

最新更新