playframework2.6でコンパイル時DIしてるとエラーハンドラが動作しなかった。
色々調べた結果、以下のようにApplicationLoaderでオーバーライドすると動いた。
MyAppllicationLoader.scala
package com.exsample
import _root_.controllers.AssetsComponents
import play.api.ApplicationLoader.Context
import play.api._
import play.filters.HttpFiltersComponents
import router.Routes
import com.exsample.controllers._
class MyApplicationLoader extends ApplicationLoader {
def load(context: Context) = {
LoggerConfigurator(context.environment.classLoader).foreach {
_.configure(context.environment, context.initialConfiguration, Map.empty)
}
new MyApplicationComponents(context).application
}
}
class MyApplicationComponents(context: Context)
extends BuiltInComponentsFromContext(context) with AssetsComponents
with HttpFiltersComponents {
// httpErrorHandlerをoverrideする
override lazy val httpErrorHandler = new ErrorHandler()
lazy val sampleController = new SampleController(controllerComponents)
// router
lazy val router = new Routes(httpErrorHandler, sampleController, assets)
}
参考
https://groups.google.com/forum/#!topic/lagom-framework/R-K0H2RdYnw