我正在尝试在我的Play+Scala应用程序(2.5x)中使用DeadBolt.我在我的build.sbt (Play 2.5x)中添加了以下内容:
libraryDependencies += "be.objectify" %% "deadbolt-scala" % "2.5.1"在我的conf/application.conf中:
enabled += "be.objectify.deadbolt.scala.DeadboltModule"在"sbt run“之后,当我访问服务器时,我立即得到这个错误:
play.api.UnexpectedException: Unexpected exception[CreationException: Unable to create injector, see the following errors:
1) No implementation for be.objectify.deadbolt.scala.cache.HandlerCache was bound.
while locating be.objectify.deadbolt.scala.cache.HandlerCache
for parameter 1 at be.objectify.deadbolt.scala.ActionBuilders.<init>(ActionBuilders.scala:30)
at be.objectify.deadbolt.scala.DeadboltModule.bindings(DeadboltModule.scala:32):
Binding(class be.objectify.deadbolt.scala.ActionBuilders to self) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
2) No implementation for be.objectify.deadbolt.scala.cache.HandlerCache was bound.
while locating be.objectify.deadbolt.scala.cache.HandlerCache
for parameter 1 at be.objectify.deadbolt.scala.DeadboltActions.<init>(DeadboltActions.scala:34)
at be.objectify.deadbolt.scala.DeadboltModule.bindings(DeadboltModule.scala:30):
Binding(class be.objectify.deadbolt.scala.DeadboltActions to self) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
2 errors]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:180)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:131)
at scala.Option.map(Option.scala:146)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:131)
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:129)
at scala.util.Success.flatMap(Try.scala:231)我没有做任何其他的代码更改。为什么即使我还没有写任何代码来使用Deadbolt,它也会失败?
发布于 2017-09-18 18:33:26
它不能工作,因为它需要实现某些接口,并绑定到DI中。因此,您不能简单地插入依赖项,然后期望它能正常工作。
您至少需要DI绑定:
TemplateFailureListener HandlerCache DeadboltExecutionContextProvider
在https://github.com/schaloner/deadbolt-2-scala-examples上提供了一个可用的示例
https://stackoverflow.com/questions/46272041
复制相似问题