Play框架插件被Module替换,

时间:2016-02-11 04:28:29

标签: mongodb playframework guice

在Play框架中插件被Module替换, 我的问题是如何在模块中实现onStart()和onStop()方法。 因为我使用插件来使用onStart()方法初始化mongodb实例,但是模块没有提供这些功能。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

来自https://www.playframework.com/documentation/2.4.x/PluginsToModules

import javax.inject.Inject
import play.api.inject.ApplicationLifecycle
import scala.concurrent.Future

trait MyComponent

class MyComponentImpl @Inject()(lifecycle: ApplicationLifecycle) extends MyComponent {
  // previous contents of Plugin.onStart
  lifecycle.addStopHook { () =>
    // previous contents of Plugin.onStop
    Future.successful(())
  }
}