如何在 Play 2.5 中激活循环依赖?

How to activate circular dependencies in Play 2.5?

这个问题源于question that I asked two days ago. I implemented my own error handler which extends DefaultHttpErrorHandler. DefaultHttpErrorHandler extends HttpErrorHandler which is also used as a parameter errorHandler: HttpErrorHandler in the WebJarAssets class. First I thought I had a flaw in my design, but James Ward评论说看来我做的事情是对的

长话短说,我需要知道如何激活循环依赖。不幸的是,Play documentation 中没有列出示例代码,所以我不知道应该在哪里设置 disableCircularProxies(false)

您需要自定义 GuiceApplicationLoader,例如:

import play.api.ApplicationLoader
import play.api.inject.guice.{GuiceApplicationLoader, GuiceApplicationBuilder}

class CustomApplicationLoader extends GuiceApplicationLoader {
  override protected def builder(context: ApplicationLoader.Context): GuiceApplicationBuilder = {
    super.builder(context).disableCircularProxies(false)
  }
}

并告诉 Play 在 application.conf:

中使用它
play.application.loader = "CustomApplicationLoader"

完整代码示例: https://github.com/webjars/webjars-play/tree/cicular-deps