我在 Scaldi 中注入光滑的 DatabaseConfigProvider 时遇到问题。它在 play 2.4 中运行良好,但我不得不迁移到 2.5。
这是我的配置:
- 玩 2.5.3
- scaldi-play 0.5.15
- 玩滑 2.0.0
我的应用程序配置:
slick.dbs.devpostgres.driver="slick.driver.PostgresDriver$" # You must provide the required Slick driver!
slick.dbs.devpostgres.db.driver=org.postgresql.Driver
slick.dbs.devpostgres.db.url="jdbc:postgresql://localhost:5432/test"
slick.dbs.devpostgres.db.user=postgres
slick.dbs.devpostgres.db.password="pwd"
play.application.loader = scaldi.play.ScaldiApplicationLoader
play.modules {
enabled += modules.ApplicationModule
enabled += scaldi.play.ControllerInjector
}
我的 Scaldi 应用程序模块:
class ApplicationModule extends Module {
binding to new ObjectDao
binding to new UserDao
bind[DatabaseConfig[_]] to DatabaseConfigProvider.get[JdbcProfile]("devpostgres")(inject[Application])
}
我的 ObjectDao 由我的 UserDao 类扩展:
class ObjectDao(implicit inj: Injector) extends Injectable {
// Using the same database connection for every DAO extending this class
val dbConfig = inject[DatabaseConfigProvider].get[JdbcProfile]
val db = dbConfig.db
}
最后,我的 UserDao :
class UserDao(implicit inj: Injector) extends ObjectDao {
import dbConfig.driver.api._
private val users = TableQuery[UserTable]
...
}
启动应用程序时出错:
Unexpected exception
InjectException: No binding found with following identifiers:
* TypeTagIdentifier(play.api.db.slick.DatabaseConfigProvider)
No source available, here is the exception stack trace:
->scaldi.InjectException: No binding found with following identifiers:
* TypeTagIdentifier(play.api.db.slick.DatabaseConfigProvider)
scaldi.Injectable$class.noBindingFound(Injectable.scala:180)
dao.ObjectDao.noBindingFound(ObjectDao.scala:7)
scaldi.Injectable$$anonfun$inject$1$$anonfun$apply$1.apply(Injectable.scala:45)
scaldi.Injectable$$anonfun$inject$1$$anonfun$apply$1.apply(Injectable.scala:45)
scala.Option.getOrElse(Option.scala:121)
scaldi.Injectable$class.injectWithDefault(Injectable.scala:152)
dao.ObjectDao.injectWithDefault(ObjectDao.scala:7)
scaldi.Injectable$$anonfun$inject$1.apply(Injectable.scala:45)
scaldi.Injectable$$anonfun$inject$1.apply(Injectable.scala:45)
scaldi.util.Util$WorkflowHelper$.$bar$greater$extension(Util.scala:7)
scaldi.Injectable$class.inject(Injectable.scala:45)
dao.ObjectDao.inject(ObjectDao.scala:7)
dao.ObjectDao.(ObjectDao.scala:9)
dao.UserDao.(AdminRepo.scala:13)
modules.ApplicationModule$$anonfun$3.apply(ApplicationModule.scala:64)
modules.ApplicationModule$$anonfun$3.apply(ApplicationModule.scala:64)
scaldi.LazyBinding$$anonfun$target$2.apply(Binding.scala:180)
scaldi.LazyBinding$$anonfun$target$2.apply(Binding.scala:180)
scala.Option.map(Option.scala:146)
scaldi.LazyBinding.target$lzycompute(Binding.scala:180)
scaldi.LazyBinding.target(Binding.scala:180)
scaldi.LazyBinding.get(Binding.scala:196)
scaldi.Binding$$anon$1.get(Binding.scala:66)
scaldi.Injectable$$anonfun$injectWithDefault$1.apply(Injectable.scala:152)
scaldi.Injectable$$anonfun$injectWithDefault$1.apply(Injectable.scala:152)
scala.Option.flatMap(Option.scala:171)
scaldi.Injectable$class.injectWithDefault(Injectable.scala:152)
controllers.Application.injectWithDefault(Application.scala:16)
scaldi.Injectable$$anonfun$inject$1.apply(Injectable.scala:45)
scaldi.Injectable$$anonfun$inject$1.apply(Injectable.scala:45)
scaldi.util.Util$WorkflowHelper$.$bar$greater$extension(Util.scala:7)
scaldi.Injectable$class.inject(Injectable.scala:45)
controllers.Application.inject(Application.scala:16)
controllers.Application.(Application.scala:18)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:422)
scala.reflect.runtime.JavaMirrors$JavaMirror$JavaVanillaMethodMirror1.jinvokeraw(JavaMirrors.scala:374)
scala.reflect.runtime.JavaMirrors$JavaMirror$JavaMethodMirror.jinvoke(JavaMirrors.scala:339)
scala.reflect.runtime.JavaMirrors$JavaMirror$JavaVanillaMethodMirror.apply(JavaMirrors.scala:355)
scaldi.play.ControllerInjector$$anonfun$4.apply(ControllerInjector.scala:62)
scaldi.play.ControllerInjector$$anonfun$4.apply(ControllerInjector.scala:53)
scala.Option.map(Option.scala:146)
scaldi.play.ControllerInjector.scaldi$play$ControllerInjector$$createBinding(ControllerInjector.scala:53)
scaldi.play.ControllerInjector$$anonfun$getBindingInternal$3$$anonfun$apply$3.apply(ControllerInjector.scala:33)
scaldi.play.ControllerInjector$$anonfun$getBindingInternal$3$$anonfun$apply$3.apply(ControllerInjector.scala:32)
scala.Option.getOrElse(Option.scala:121)
scaldi.play.ControllerInjector$$anonfun$getBindingInternal$3.apply(ControllerInjector.scala:32)
scaldi.play.ControllerInjector$$anonfun$getBindingInternal$3.apply(ControllerInjector.scala:31)
scala.Option.getOrElse(Option.scala:121)
scaldi.play.ControllerInjector.getBindingInternal(ControllerInjector.scala:30)
scaldi.MutableInjectorAggregation$$anonfun$getBindingInternal$2.apply(Injector.scala:85)
scaldi.MutableInjectorAggregation$$anonfun$getBindingInternal$2.apply(Injector.scala:84)
scala.collection.Iterator$$anon$11.next(Iterator.scala:370)
scala.collection.TraversableOnce$class.collectFirst(TraversableOnce.scala:143)
scala.collection.SeqViewLike$AbstractTransformed.collectFirst(SeqViewLike.scala:37)
scaldi.MutableInjectorAggregation.getBindingInternal(Injector.scala:87)
scaldi.InjectorWithLifecycle$$anonfun$getBinding$3.apply(Injector.scala:170)
scaldi.InjectorWithLifecycle$$anonfun$getBinding$3.apply(Injector.scala:170)
scaldi.util.Util$WorkflowHelper$.$bar$greater$extension(Util.scala:7)
scaldi.InjectorWithLifecycle$class.getBinding(Injector.scala:170)
scaldi.MutableInjectorAggregation.getBinding(Injector.scala:78)
scaldi.jsr330.AnnotationBinding.scaldi$jsr330$AnnotationBinding$$injectSymbol(AnnotationBinding.scala:171)
scaldi.jsr330.AnnotationBinding$$anonfun$22.apply(AnnotationBinding.scala:132)
scaldi.jsr330.AnnotationBinding$$anonfun$22.apply(AnnotationBinding.scala:132)
scala.collection.immutable.List.map(List.scala:277)
scaldi.jsr330.AnnotationBinding.scaldi$jsr330$AnnotationBinding$$createNewInstance(AnnotationBinding.scala:132)
scaldi.jsr330.AnnotationBinding$$anonfun$2$$anonfun$apply$2.apply(AnnotationBinding.scala:41)
scaldi.jsr330.AnnotationBinding$$anonfun$2$$anonfun$apply$2.apply(AnnotationBinding.scala:41)
scaldi.jsr330.AnnotationBinding.initNewInstance(AnnotationBinding.scala:119)
scaldi.jsr330.AnnotationBinding.getInstance(AnnotationBinding.scala:111)
scaldi.jsr330.AnnotationBinding.get(AnnotationBinding.scala:85)
scaldi.Binding$$anon$1.get(Binding.scala:66)
scaldi.play.ScaldiInjector$$anonfun$scaldi$play$ScaldiInjector$$getActualBinding$1$$anonfun$apply$2.apply(ScaldiInjector.scala:42)
scaldi.play.ScaldiInjector$$anonfun$scaldi$play$ScaldiInjector$$getActualBinding$1$$anonfun$apply$2.apply(ScaldiInjector.scala:42)
scala.Option.map(Option.scala:146)
scaldi.play.ScaldiInjector$$anonfun$scaldi$play$ScaldiInjector$$getActualBinding$1.apply(ScaldiInjector.scala:42)
scaldi.play.ScaldiInjector$$anonfun$scaldi$play$ScaldiInjector$$getActualBinding$1.apply(ScaldiInjector.scala:38)
play.utils.Threads$.withContextClassLoader(Threads.scala:21)
scaldi.play.ScaldiInjector.scaldi$play$ScaldiInjector$$getActualBinding(ScaldiInjector.scala:38)
scaldi.play.ScaldiInjector$$anonfun$instanceOf$1.apply(ScaldiInjector.scala:23)
scaldi.play.ScaldiInjector$$anonfun$instanceOf$1.apply(ScaldiInjector.scala:22)
scala.Option.getOrElse(Option.scala:121)
scaldi.play.ScaldiInjector.instanceOf(ScaldiInjector.scala:22)
scaldi.play.ScaldiInjector.instanceOf(ScaldiInjector.scala:18)
play.api.inject.RoutesProvider$$anonfun$2.apply(BuiltinModule.scala:82)
play.api.inject.RoutesProvider$$anonfun$2.apply(BuiltinModule.scala:82)
scala.Option.fold(Option.scala:158)
play.api.inject.RoutesProvider.get$lzycompute(BuiltinModule.scala:82)
play.api.inject.RoutesProvider.get(BuiltinModule.scala:78)
play.api.inject.RoutesProvider.get(BuiltinModule.scala:77)
scaldi.play.ScaldiBuilder$$anonfun$6$$anonfun$apply$1$$anonfun$apply$12.apply(ScaldiBuilder.scala:227)
scaldi.ProviderBinding.target(Binding.scala:217)
scaldi.ProviderBinding.get(Binding.scala:223)
scaldi.ProviderBinding.get(Binding.scala:213)
scaldi.Binding$$anon$1.get(Binding.scala:66)
scaldi.jsr330.AnnotationBinding$$anonfun$scaldi$jsr330$AnnotationBinding$$injectSymbol$2.apply(AnnotationBinding.scala:171)
scaldi.jsr330.AnnotationBinding$$anonfun$scaldi$jsr330$AnnotationBinding$$injectSymbol$2.apply(AnnotationBinding.scala:171)
scala.Option.flatMap(Option.scala:171)
scaldi.jsr330.AnnotationBinding.scaldi$jsr330$AnnotationBinding$$injectSymbol(AnnotationBinding.scala:171)
scaldi.jsr330.AnnotationBinding$$anonfun$22.apply(AnnotationBinding.scala:132)
scaldi.jsr330.AnnotationBinding$$anonfun$22.apply(AnnotationBinding.scala:132)
scala.collection.immutable.List.map(List.scala:273)
scaldi.jsr330.AnnotationBinding.scaldi$jsr330$AnnotationBinding$$createNewInstance(AnnotationBinding.scala:132)
scaldi.jsr330.AnnotationBinding$$anonfun$2$$anonfun$apply$2.apply(AnnotationBinding.scala:41)
scaldi.jsr330.AnnotationBinding$$anonfun$2$$anonfun$apply$2.apply(AnnotationBinding.scala:41)
scaldi.jsr330.AnnotationBinding.initNewInstance(AnnotationBinding.scala:119)
scaldi.jsr330.AnnotationBinding.getInstance(AnnotationBinding.scala:111)
scaldi.jsr330.AnnotationBinding.get(AnnotationBinding.scala:85)
scaldi.Binding$$anon$1.get(Binding.scala:66)
scaldi.Injectable$$anonfun$injectWithDefault$1.apply(Injectable.scala:152)
scaldi.Injectable$$anonfun$injectWithDefault$1.apply(Injectable.scala:152)
scala.Option.flatMap(Option.scala:171)
scaldi.Injectable$class.injectWithDefault(Injectable.scala:152)
scaldi.play.ScaldiBuilder$.injectWithDefault(ScaldiBuilder.scala:128)
scaldi.play.ScaldiBuilder$$anonfun$6$$anonfun$apply$1$$anonfun$apply$18.apply(ScaldiBuilder.scala:240)
scaldi.ProviderBinding.target(Binding.scala:217)
scaldi.ProviderBinding.get(Binding.scala:223)
scaldi.ProviderBinding.get(Binding.scala:213)
scaldi.Binding$$anon$1.get(Binding.scala:66)
scaldi.jsr330.AnnotationBinding$$anonfun$scaldi$jsr330$AnnotationBinding$$injectSymbol$2.apply(AnnotationBinding.scala:171)
scaldi.jsr330.AnnotationBinding$$anonfun$scaldi$jsr330$AnnotationBinding$$injectSymbol$2.apply(AnnotationBinding.scala:171)
scala.Option.flatMap(Option.scala:171)
scaldi.jsr330.AnnotationBinding.scaldi$jsr330$AnnotationBinding$$injectSymbol(AnnotationBinding.scala:171)
scaldi.jsr330.AnnotationBinding$$anonfun$22.apply(AnnotationBinding.scala:132)
scaldi.jsr330.AnnotationBinding$$anonfun$22.apply(AnnotationBinding.scala:132)
scala.collection.immutable.List.map(List.scala:277)
scaldi.jsr330.AnnotationBinding.scaldi$jsr330$AnnotationBinding$$createNewInstance(AnnotationBinding.scala:132)
scaldi.jsr330.AnnotationBinding$$anonfun$2$$anonfun$apply$2.apply(AnnotationBinding.scala:41)
scaldi.jsr330.AnnotationBinding$$anonfun$2$$anonfun$apply$2.apply(AnnotationBinding.scala:41)
scaldi.jsr330.AnnotationBinding.initNewInstance(AnnotationBinding.scala:119)
scaldi.jsr330.AnnotationBinding.getInstance(AnnotationBinding.scala:111)
scaldi.jsr330.AnnotationBinding.get(AnnotationBinding.scala:85)
scaldi.Binding$$anon$1.get(Binding.scala:66)
scaldi.Injectable$$anonfun$injectWithDefault$1.apply(Injectable.scala:152)
scaldi.Injectable$$anonfun$injectWithDefault$1.apply(Injectable.scala:152)
scala.Option.flatMap(Option.scala:171)
scaldi.Injectable$class.injectWithDefault(Injectable.scala:152)
scaldi.play.ScaldiBuilder$.injectWithDefault(ScaldiBuilder.scala:128)
scaldi.play.ScaldiBuilder$$anonfun$6$$anonfun$apply$1$$anonfun$apply$18.apply(ScaldiBuilder.scala:240)
scaldi.ProviderBinding.target(Binding.scala:217)
scaldi.ProviderBinding.get(Binding.scala:223)
scaldi.ProviderBinding.get(Binding.scala:213)
scaldi.Binding$$anon$1.get(Binding.scala:66)
scaldi.play.ScaldiInjector$$anonfun$scaldi$play$ScaldiInjector$$getActualBinding$1$$anonfun$apply$2.apply(ScaldiInjector.scala:42)
scaldi.play.ScaldiInjector$$anonfun$scaldi$play$ScaldiInjector$$getActualBinding$1$$anonfun$apply$2.apply(ScaldiInjector.scala:42)
scala.Option.map(Option.scala:146)
scaldi.play.ScaldiInjector$$anonfun$scaldi$play$ScaldiInjector$$getActualBinding$1.apply(ScaldiInjector.scala:42)
scaldi.play.ScaldiInjector$$anonfun$scaldi$play$ScaldiInjector$$getActualBinding$1.apply(ScaldiInjector.scala:38)
play.utils.Threads$.withContextClassLoader(Threads.scala:21)
scaldi.play.ScaldiInjector.scaldi$play$ScaldiInjector$$getActualBinding(ScaldiInjector.scala:38)
scaldi.play.ScaldiInjector$$anonfun$instanceOf$1.apply(ScaldiInjector.scala:23)
scaldi.play.ScaldiInjector$$anonfun$instanceOf$1.apply(ScaldiInjector.scala:22)
scala.Option.getOrElse(Option.scala:121)
scaldi.play.ScaldiInjector.instanceOf(ScaldiInjector.scala:22)
scaldi.play.ScaldiInjector.instanceOf(ScaldiInjector.scala:18)
scaldi.play.ScaldiInjector.instanceOf(ScaldiInjector.scala:15)
scaldi.play.ScaldiApplicationBuilder.build(ScaldiApplicationBuilder.scala:88)
scaldi.play.ScaldiApplicationLoader.load(ScaldiApplicationLoader.scala:19)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:158)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:155)
play.utils.Threads$.withContextClassLoader(Threads.scala:21)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:155)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:126)
scala.Option.map(Option.scala:146)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:126)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:124)
scala.util.Success.flatMap(Try.scala:231)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:124)
play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:116)
scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
我在这里错过了什么吗?
在此先感谢您的帮助。
非常感激 !