我在play框架中使用Silhouette库时遇到了问题,我使用guice进行运行时依赖注入,在创建接受DelegableAuthInfoDAO作为参数的DelegableAuthInfoRepository时出现错误,它指出即使我在configure方法中做了绑定,DelegableAuthInfoDAO也没有绑定到具体实例,这是我在启用模块时得到的错误
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())
}发布于 2018-03-15 23:07:53
这是可行的:
bind(new TypeLiteral[DelegableAuthInfoDAO[PasswordInfo]]{}).toInstance(new InMemoryAuthInfoDAO[PasswordInfo])https://stackoverflow.com/questions/47179095
复制相似问题