问题
I am getting these error ProvisionException: Unable to provision, see the following errors:
com.google.inject.ProvisionException: Unable to provision, see the following errors:
1) Could not find a suitable constructor in models.factory.FactoryHandler. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
at models.factory.FactoryHandler.class(FactoryHandler.scala:7)
while locating models.factory.FactoryHandler
for parameter 0 at controllers.DirectUserController.<init>(DirectUserController.scala:90)
while locating 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
com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1025)
com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051)
play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:321)
play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:316)
play.api.Application$class.routes(Application.scala:111)
play.api.DefaultApplication.routes(Application.scala:240)
play.api.Play$$anonfun$start$1.apply$mcV$sp(Play.scala:90)
play.api.Play$$anonfun$start$1.apply(Play.scala:87)
play.api.Play$$anonfun$start$1.apply(Play.scala:87)
play.utils.Threads$.withContextClassLoader(Threads.scala:21)
play.api.Play$.start(Play.scala:87)
here is the code
class FactoryHandler(var s:String="real") {
val log = LoggerFactory.getLogger(this.getClass)
log.debug("choice {}",s)
}
and this is line no 90 at DirectUserController
class DirectUserController @Inject() (var factory:FactoryHandler) extends Controller {
//other Action code
}
I have also added code in routes file
routesGenerator := InjectedRoutesGenerator
i am using play framework 2.4 please help me why i am getting this error
回答1:
You need to specify a @Inject() in FactoryHandler code.. read the error, I think it says what's wrong with it.
来源:https://stackoverflow.com/questions/44862314/provisionexception-unable-to-provision-in-play-framework