でアノテートさのどちらか1つだけのコンストラクタを持っている必要があります私はPlayFrameworkでGuiceのを使用していますが、私はランタイムエラーを取得しています:ここでProvisionException:クラスが@Injectまたはゼロ引数
Caused by: com.google.inject.ProvisionException: Unable to provision, see the following errors:
1) Could not find a suitable constructor in controllers.DirectUserController. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
at controllers.DirectUserController.class(DirectUserController.scala:90)
while locating com.google.inject.Provider<controllers.DirectUserController>
for parameter 7 at router.Routes.<init>(Routes.scala:124)
while locating router.Routes
while locating play.api.inject.RoutesProvider
while locating play.api.routing.Router
1 error
at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1025) ~[guice-4.0.jar:na]
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051) ~[guice-4.0.jar:na]
at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:321) ~[play_2.11-2.4.3.jar:2.4.3]
at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:316) ~[play_2.11-2.4.3.jar:2.4.3]
at play.api.Application$class.routes(Application.scala:111) ~[play_2.11-2.4.3.jar:2.4.3]
はコードです:私が追加したbuild.sbt
で
class DirectUserController(var factory:FactoryHandlerTrait) extends Controller {
//rest of the code
}
:
trait FactoryHandlerTrait {
def getDirectUserFactory: DirectUserFactory
def getUserRepository: UserRepository
def getUrlRepository: URLRepository
}
class FactoryHandler(var s: String = "real") extends FactoryHandlerTrait {
def getDirectUserFactory: DirectUserFactory = {
//implementation here
}
def getUserRepository: UserRepository = {
//implementation here
}
def getUrlRepository: URLRepository = {
//implementation here
}
}
class DependencyModule extends Module {
def configure(binder: Binder) = {
binder.bind(classOf[FactoryHandlerTrait]).to(classOf[FactoryHandler])
}
}
そして、ここでは私のコントローラであります:
routesGenerator := InjectedRoutesGenerator
何が間違っているのですか?その例外を避けるには?
私はPlay 2.4.3とGuice 3.0を使用しています。