我重寫注入依賴概念上的類HttpErrorHandler
,並嘗試處理路由頁面。當URL的路由頁面不正確時,我不需要Action not found
頁面,但它必須通過指定頁面路徑的HttpPageErrorHandler
來呈現。圖如下面時嘗試訪問的網址不包含參數指定爲如何使用依賴注入播放框架處理「未找到操作」2.4
GET /adminlanding/:userId/:ip/:dateFound/ controllers.DashboardAdmin.landing(userId: String, ip : String, dateFound : String)
HttpPageErrorHandler
http://localhost:9000/adminlanding
路由頁面處理Action not found
class HttpPageErrorHandler @Inject() (router: Router) extends HttpErrorHandler {
private def errorHandler = Play.maybeApplication.fold[HttpErrorHandler](DefaultHttpErrorHandler)(_.errorHandler)
def onClientError(request: RequestHeader, statusCode: Int, message: String) : Future[Result]= {
statusCode match {
case Status.NOT_FOUND =>
Future.successful(NotFound(views.html.errors.notFoundPage(request)))
case clientError if statusCode >= 400 && statusCode < 500 =>
Future.successful(Forbidden(views.html.errors.notFoundPage(request)))
}
}
def onServerError(request: RequestHeader, exception: Throwable): Future[Result] = {
errorHandler.onServerError(request, exception)
}
}
Application.conf聲明配置調用注入類
play.http.HttpErrorHandler = RequestHandler
與sbt run
劇照運行命令行後顯示Action not found
頁。
同樣的問題在這裏。 – chabeee