ProvisionException:无法在play框架中进行配置

时间:2017-07-01 14:56:56

标签: java scala playframework playframework-2.4

我收到这些错误 ProvisionException:无法配置,请参阅以下错误:

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)

这是代码

class FactoryHandler(var s:String="real") {
  val log = LoggerFactory.getLogger(this.getClass)
  log.debug("choice {}",s)
}

这是DirectUserController的第90行

    class DirectUserController @Inject() (var factory:FactoryHandler) extends Controller {
//other Action code 
}

我还在路线文件中添加了代码

routesGenerator := InjectedRoutesGenerator

我正在使用play framework 2.4请帮助我,为什么我收到此错误

1 个答案:

答案 0 :(得分:0)

你需要在FactoryHandler代码中指定一个@Inject()..读错误,我认为它说错了。