【问题标题】:Silhouette Unexpected exception playframework 2.6剪影意外异常playframework 2.6
【发布时间】:2018-04-21 02:29:52
【问题描述】:

我在播放框架中使用 Silhouette 库时遇到问题,我正在使用 guice 进行运行时依赖注入,创建接受 DelegableAuthInfoDAO 作为参数的 DelegableAuthInfoRepository 时出错,它说 DelegableAuthInfoDAO 未绑定到具体实例,即使我在configure方法中做了一个绑定,这是我启用模块时遇到的错误

play.api.UnexpectedException: Unexpected exception[CreationException: Unable 
to create injector, see the following errors:

1) No implementation for 
com.mohiva.play.silhouette.persistence. 
daos.DelegableAuthInfoDAO<com.mohiva.pla
y.silhouette.api.util.PasswordInfo> was bound.
while locating 


com.mohiva.play.silhouette.persistence.daos 
.DelegableAuthInfoDAO<com.mohiva.play
.silhouette.api.util.PasswordInfo>
for the 1st parameter of 
modules.authModule.provideAuthInfoRepository(authModule.scala:112)
at modules.authModule.provideAuthInfoRepository(authModule.scala:112) (via 
modules: com.google.inject.util.Modules$OverrideModule -> 
modules.authModule)

这是模块中完成的一些配置:

@Provides
def provideAuthInfoRepository(passwordInfoDAO: DelegableAuthInfoDAO[PasswordInfo]): AuthInfoRepository = {
  new DelegableAuthInfoRepository(passwordInfoDAO)
}

override def configure() = {
  bind(classOf[UserDAO]).asEagerSingleton()
  bind(classOf[IdentityService[User]]).to(classOf[UserService])
  bind(classOf[CacheLayer]).to(classOf[PlayCacheLayer])

  bind(classOf[PasswordHasher]).toInstance(new BCryptPasswordHasher())
  bind(classOf[EventBus]).toInstance(new EventBus)
  bind(classOf[DelegableAuthInfoDAO[PasswordInfo]]).toInstance(new InMemoryAuthInfoDAO[PasswordInfo]())
  bind(classOf[IDGenerator]).toInstance(new SecureRandomIDGenerator())
  bind(classOf[FingerprintGenerator]).toInstance(new DefaultFingerprintGenerator(false))
  bind(classOf[Clock]).toInstance(Clock())
}

【问题讨论】:

    标签: scala playframework-2.0 guice playframework-2.6 silhouette


    【解决方案1】:

    这行得通:

    bind(new TypeLiteral[DelegableAuthInfoDAO[PasswordInfo]]{}).toInstance(new InMemoryAuthInfoDAO[PasswordInfo])
    

    【讨论】:

      猜你喜欢
      • 2020-07-28
      • 2019-05-05
      • 2018-06-28
      • 2018-09-26
      • 2019-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-11
      相关资源
      最近更新 更多