Custom Router in Playframework 2.4
I'm using Play 2.4. I'd like to replace the default router, with my own class, using the new dynamic dependency injection play feature. What are the steps to do that?
One possible solution would be to create a new Guice Module, to bind your new router:
class RouterModule extends AbstractModule {
override def configure(): Unit = {
bind(classOf[Router]).to(classOf[CustomRouter])
}
}
Then define a new Application Loader, which will override the default configured router, by using the newly created module:
class MyApplicationLoader extends GuiceApplicationLoader with GuiceableModuleConversions {
override protected def overrides(context: Context): Seq[GuiceableModule] = {
Seq(fromGuiceModule(new RouterModule)) ++ super.overrides(context)
}
}
And use the newly created application loader, instead of the default one, in application.conf:
play.application.loader = "de.zalando.store.pdp.modules.MyApplicationLoader"
链接地址: http://www.djcxy.com/p/26492.html