我重写注入依赖概念上的类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