0
我有一个使用play 2.5框架开发的宁静的网络服务。 我想通过调用自己来启动我的Web服务。这是为了确保我的服务完全正常运行。播放2.5启动网络服务
我采取的方法是使用eagerBinding。但是类中的代码使用注入的渴望结合被执行之前的应用程序启动
这里是我的eagerbinding代码看起来像
@Singleton
class PrimingMe @Inject()(ws: WSClient) {
isServicePrimed
def isServicePrimed: Boolean = {
println("PRIME ME!!!")
val response = ws.url("http://localhost:9000/index").get
.map {
response =>
response.status match {
case 200 => true
case _ => false
}
}
try {
Await.result(response, 5.second)
} catch {
case _ => false
}
}
}
class ServiceInjectionModule extends AbstractModule {
def configure(): Unit = {
bind(classOf[PrimingMe]).asEagerSingleton
}
}
内application.conf
play.modules.enabled += "util.ServiceInjectionModule"
我想用虚拟服务调用来填充我的应用程序,这样当真正的流量开始时,所有的数据库连接都会被创建。目前,我对服务的第一个API调用比平时花费的时间长得多。我还有什么其他选择可以实现这一点。
为什么它必须是第一个模块? – rethab
@rethab以防万一初始化顺序很重要... – pamu
这是正确的工作,我不得不开始我的应用程序与sbt编译开始。然而问题是我不能在服务开始之前就打电话给'我自己'。让我重述一下这个问题。 – konquestor