LoginSignup
0
0

More than 5 years have passed since last update.

play2.6でコンパイルDIするとエラーハンドラが動かなかったときのメモ

Posted at

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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0