【发布时间】:2015-08-04 03:49:46
【问题描述】:
我使用的是 Play 2.4。我想用我自己的类替换默认路由器,使用新的动态依赖注入播放功能。这样做的步骤是什么?
【问题讨论】:
标签: scala playframework url-routing playframework-2.4
我使用的是 Play 2.4。我想用我自己的类替换默认路由器,使用新的动态依赖注入播放功能。这样做的步骤是什么?
【问题讨论】:
标签: scala playframework url-routing playframework-2.4
一种可能的解决方案是创建一个新的 Guice 模块来绑定您的新路由器:
class RouterModule extends AbstractModule {
override def configure(): Unit = {
bind(classOf[Router]).to(classOf[CustomRouter])
}
}
然后定义一个新的应用程序加载器,它将使用新创建的模块覆盖默认配置的路由器:
class MyApplicationLoader extends GuiceApplicationLoader with GuiceableModuleConversions {
override protected def overrides(context: Context): Seq[GuiceableModule] = {
Seq(fromGuiceModule(new RouterModule)) ++ super.overrides(context)
}
}
并在 application.conf 中使用新创建的应用程序加载器,而不是默认的:
play.application.loader = "de.zalando.store.pdp.modules.MyApplicationLoader"
【讨论】: