我正在使用 Deadbolt2
授权。当我,extends
DeadboltHandler
并覆盖他们的方法,我在eclipse中遇到以下错误:
implements be.objectify.deadbolt.scala.DeadboltHandler.getSubject
overriding method getSubject in trait DeadboltHandler of type [A](request: play.api.mvc.Request[A])Option[be.objectify.deadbolt.core.models.Subject]; method getSubject has incompatible type
getSubject
上产生方法,因为它的返回类型。我将它的返回类型声明为 Future[Option[Subject]]
当我使用 Option[Subject]
作为返回类型,错误被删除。当我看到 steve
的示例时https://github.com/schaloner/deadbolt-2-scala-examples/blob/master/app/security/MyDeadboltHandler.scala ,他用了Future[Option[Subject]]
当我在eclipse中导入代码时,代码没有错误。当我使用 activator clean compile
编译代码时命令没有编译时错误。override def getSubject[A](request: Request[A]): Future[Option[Subject]] = {
println("Method Start getSubject");
if(!request.headers.get("userId").isEmpty){
println("If Method Start getSubject");
val userId = request.headers.get("userId").get;
userDao.findById(BSONObjectID.apply(userId));
}else{
println("Else Method Start getSubject");
Future(Option.empty);
}}
be.objectify" %% "deadbolt-scala" % "2.3.2
依赖版本,我在 Eclipse 中得到编译时错误并成功构建运行。但是当我使用 be.objectify" %% "deadbolt-scala" % "2.3.3
依赖版本我也得到构建错误。
最佳答案
getSubject 的签名在 2.3.3 中更改,因为与 View 层的集成存在缺陷。这些例子也需要更新。
在 v2.4(Java 和 Scala 版本)中,所有接口(interface)都将返回 Futures,并且在需要阻塞调用时,例如受模板限制,将有自动包装所需的接口(interface)适配器。
请参阅 https://github.com/schaloner/deadbolt-2-scala 的自述文件中的 2.3.3 发行说明- 具体来说,这个位
DeadboltHandler#getSubject returns an Option[Subject] in place of an Future[Option[Subject]]. Where the subject is needed, the internal code will take care of wrapping the call in a Future.
关于scala - 使用 Deadbolt 2 : overriding method getSubject in trait DeadboltHandler of type 玩框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30002646/
相关文章:
sql - 在插入第三个表之前,如何使用触发器从两个表中获取日期?
jsf - ServletContext.TEMPDIR无法解析或不是字段
c# - 类数组使用产生错误 "NullReferenceException: Object ref
vba - Excel VBA : Print sheet code not working
compilation - 在Cygwin上编译GRUB(64位)
android - 按下按钮后应用程式当机,但 Action 正常
compiler-errors - ifort composer_xe_2015.3.187的编译问