Search code examples
scalaplayframeworkguicewebjarsplayframework-2.5

How to activate circular dependencies in Play 2.5?


This question originates from a 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 commented that it seems like that I am doing things right.

Long story short, I need to know how I can activate circular dependencies. Unfortunately, there is no example code listed in the Play documentation, so I have no idea where I should set disableCircularProxies(false).


Solution

  • You need a custom GuiceApplicationLoader like:

    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)
      }
    }
    

    And tell Play to use it in application.conf:

    play.application.loader = "CustomApplicationLoader"
    

    Full code example: https://github.com/webjars/webjars-play/tree/cicular-deps