本文介绍了ProvisionException:无法在游戏框架中进行配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到这些错误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
我正在使用播放框架2.4,请帮助我为什么我会收到此错误
解决方案
您需要在FactoryHandler代码中指定一个@Inject().
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
解决方案
You need to specify a @Inject() in FactoryHandler code.. read the error, I think it says what's wrong with it.
这篇关于ProvisionException:无法在游戏框架中进行配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!