我正在尝试随Play 2.6一起引入的新PlayService sbt插件(我的确切Play版本是2.6.20),并且我想将以下链接中提到的应用程序的停止钩与此基于PlayService的Play一起使用项目。
https://www.playframework.com/documentation/2.6.x/JavaDependencyInjection#Stopping/cleaning-up
我的代码如下所示,
@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(GraphInterpreter.scala:519) 在 akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInterpreter.scala:482) 在 akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:378) 在 akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:588) 在 akka.stream.impl.fusing.GraphInterpreterShell $ AsyncInput.execute(ActorGraphInterpreter.scala:472) 原因:com.google.inject.CreationException:无法创建 进样器,看到以下错误:
1)没有实现play.inject.ApplicationLifecycle的实现。
在定位play.inject.ApplicationLifecycle时 com.mycompany.ltr.startup.LtrBootStrapper。(LtrBootStrapper.java:22)的第一个参数
这是否意味着PlayService应用程序不支持ApplicationLifecycle?如果是这样,在PlayService应用程序中停止挂钩等效的替代方法是什么?
谢谢。
答案 0 :(得分:0)
ApplicationLifecycle
由play.inject.BuiltInModule
提供。这是由java-core subproject提供的,PlayMinimalJava
(和## Example data
set.seed(123)
x = runif(25,0,2)
y = 3.2 * exp(1.5*x) + rnorm(25, 0.1)
## Estimate A & B
z = log(y)
Model = lm(z ~ x)
A = exp(Model$coefficients[1])
B = Model$coefficients[2]
## Visual check of answer
plot(x,y, pch=20)
X2 = seq(0,2,0.1)
Y2 = A*exp(B*X2)
lines(X2, Y2, col="red")
)会自动添加对它的依赖,而PlayService
不会。
要解决此问题,将依赖项显式添加到PlayJava
中,如下所示:
build.sbt