我正在尝试按照the documentation在Play Framework(2.6)中加载自定义错误处理程序,但收到以下错误消息-



自定义错误处理程序(app/services/ErrorHandler)

   package services

   import javax.inject.Singleton
   import play.api.http.HttpErrorHandler
   import play.api.mvc.Results._
   import play.api.mvc._

   import scala.concurrent._

   @Singleton
   class ErrorHandler extends HttpErrorHandler {

     def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
       Future.successful(
         Status(statusCode)(
           message
         )
       )
     }

     def onServerError(request: RequestHeader, exception: Throwable) = {
       Future.successful(
         InternalServerError("A server errors occurred: " + exception.getMessage)
       )
     }
   }

application.conf
   play.http.errorHandler = "com.mySite.services.ErrorHandler"

最佳答案

在您的代码中,包不是com.mySite.services。这只是services

application.conf

play.http.errorHandler = "services.ErrorHandler"

09-25 20:17