找不到参数解析器的隐式值:play.api.mvc.BodyParser [Any] [英] could not find implicit value for parameter parser: play.api.mvc.BodyParser[Any]

查看:68
本文介绍了找不到参数解析器的隐式值:play.api.mvc.BodyParser [Any]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在迁移到Play 2.6,并具有以下曾经起作用的控制器功能:

I am migrating to Play 2.6 and have the following Controller function that used to work:

object Accounts extends Controller with API {

    def all = superUser {
        implicit principal =>
            api {
                request =>
                    models.Account.all
            }
    }
}

并收到此错误:

[error]  could not find implicit value for parameter parser: play.api.mvc.BodyParser[Any]
[error]     def all = superUser {
[error]                         ^

其中:

def superUser[A](f: => Principal => Request[A] => Result)(implicit parser: BodyParser[A]): SecureAction[A] = {
    _superUser {
        user =>
            implicit val principal = data.Principal(user)
            Action(parser)(request => f(principal)(request))
    }
}

private def _superUser[A](action: String => Action[A]) = {
    play.api.mvc.Security.Authenticated(getSuperUser, onUnauthorized)(action)
}

请参见相关问题必填:play.api. mvc.Request [?] => play.api.mvc.Result 获取有关api包装函数是什么的更多信息.

Please see the related question required: play.api.mvc.Request[?] => play.api.mvc.Result for more information on what the api wrapper function is.

问题是为什么隐式参数解析器不在范围内?再次,这曾经起作用.

The question is why is the implicit parameter parser not in scope? Again, this used to work.

推荐答案

我尝试了以下操作:

import com.google.inject.Inject
import com.google.inject.Singleton

@Singleton
class Accounts @Inject() (components: ControllerComponents) extends AbstractController(components) with API {

    def all = superUser { implicit principal =>
       api(request => models.Account.all)
    } (parse.anyContent)
}

,现在可以编译而不会出现错误.我还没有测试它,因为我要修复另一个错误(请参见上面的链接).

and now it compiles without the error. I have not tested it yet since I have another error to fix (see the above link).

Accounts曾经是object,但现在它是Singleton class.有没有人对此实施方式发表评论?

Accounts used to be an object but now it is a Singleton class. Does anyone have a comment about this implementation working?

这篇关于找不到参数解析器的隐式值:play.api.mvc.BodyParser [Any]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆