【问题标题】:Play 2.5 Migration Error: Custom Action with BodyParser: could not find implicit value for parameter mat: akka.stream.Materializer播放 2.5 迁移错误:使用 BodyParser 的自定义操作:找不到参数 mat:akka.stream.Materializer 的隐式值
【发布时间】:2016-03-15 06:49:08
【问题描述】:

我有一个 Play Framework 应用程序,2.4 版正在迁移到 2.5,一切就绪!但使用 BodyParser 在我的自定义操作中引发错误,

 def isAuthenticatedAsync[A](parser: BodyParser[A])(f: => Long => Request[A] => Future[Result]) = {
Security.Authenticated(userId, onUnauthorized) { user =>
  Action.async(parser)(request => f(user)(request))
}

}

使用这个:

def upload = isAuthenticatedAsync(parse.maxLength(5 * 1024 * 1024, parse.multipartFormData)) { userId => request =>
//Logger.info(s"")
request.body match {
  case Left(MaxSizeExceeded(length)) => Future(BadRequest(Json.toJson(ResultTemp("Your file is too large, we accept just " + length + " bytes!"))))
  case Right(multipartForm) =>

抛出一个错误:

could not find implicit value for parameter mat: akka.stream.Materializer

[错误] def upload = Action.async(parse.maxLength(5 * 1024 * 1024, parse.multipartFormData)) { request =>

【问题讨论】:

    标签: scala playframework


    【解决方案1】:

    看起来你需要在你的控制器中注入一个物化器

    class MyController @Inject() (implicit val mat: Materializer) {}
    

    【讨论】:

      猜你喜欢
      • 2018-01-06
      • 1970-01-01
      • 1970-01-01
      • 2016-06-21
      • 2015-05-14
      • 2012-07-22
      • 2015-08-28
      • 2016-01-17
      • 1970-01-01
      相关资源
      最近更新 更多