ProvisionException: Unable to provision, in play framework

不想你离开。 提交于 2020-01-15 06:29:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!