PlayFramework 2.4,Actor 注入问题:没有启动的应用程序

PlayFramework 2.4, Actor injection issue: There is no started application

有人问过 ,但我觉得它不是很有帮助。我正在将 MyRepository 注入 MyActor。启动时,出现以下异常:

[error] - akka.actor.OneForOneStrategy - Unable to provision, see the following errors:

1) Error injecting constructor, java.lang.RuntimeException: There is no started application
  at infrastructure.repository.MyRepository.<init>(MyRepository.scala:13)
  at infrastructure.repository.MyRepository.class(MyRepository.scala:13)
  while locating infrastructure.repository.MyRepository
    for parameter 0 at service.command.MyActor.<init>(MyActor.scala:38)
  at service.command.MyActor.class(MyActor.scala:38)
  while locating service.command.MyActor

1 error
akka.actor.ActorInitializationException: exception during creation
        at akka.actor.ActorInitializationException$.apply(Actor.scala:172) ~[akka-actor_2.11-2.4.0.jar:na]
        at akka.actor.ActorCell.create(ActorCell.scala:605) ~[akka-actor_2.11-2.4.0.jar:na]
        at akka.actor.ActorCell.invokeAll(ActorCell.scala:460) ~[akka-actor_2.11-2.4.0.jar:na]
        at akka.actor.ActorCell.systemInvoke(ActorCell.scala:482) ~[akka-actor_2.11-2.4.0.jar:na]
        at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:282) [akka-actor_2.11-2.4.0.jar:na]
        at akka.dispatch.Mailbox.run(Mailbox.scala:223) [akka-actor_2.11-2.4.0.jar:na]
        at akka.dispatch.Mailbox.exec(Mailbox.scala:234) [akka-actor_2.11-2.4.0.jar:na]
        at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.11.7.jar:na]
        at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.11.7.jar:na]
        at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.11.7.jar:na]
        at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.11.7.jar:na]
Caused by: com.google.inject.ProvisionException: Unable to provision, see the following errors:
.... [same thing]

我已按照说明进行操作,并且我有一个类似

的模块
class InjectionModule extends AbstractModule with AkkaGuiceSupport {
  def configure = {
    bindActor[MyActor]("my-actor")
  }
}

这是 MyRepository 的代码:

@Singleton
class MyRepository @Inject()(val reactiveMongoApi: ReactiveMongoApi) extends Repository {

  // init db connection
  override val collection = getCollection(reactiveMongoApi, "card")

  def getById(id: CardId) = get(Json.obj(Entity.JSON_KEY_ID -> id.toString))

  // .. other similar methods
}


abstract class Repository {
  val collection: JSONCollection

  val dbName = current.configuration.getString("mongodb.database.name").getOrElse("")

  protected def getCollection(reactiveMongoApi: ReactiveMongoApi, name: String) =
    reactiveMongoApi.connection.db(dbName, FailoverStrategy(initialDelay = 1.second, retries = 20)).collection[JSONCollection](name)

  protected def get(query: JsObject): Future[Either[String, Option[A]]] = {
    collection.find(query).one[A].map {
      case Some(a) => Right(Some(a))
      case None => Right(None)
    }.recover { case t => Left(t.getMessage) }
  }

  // ... similar methods
}

这是 MyActor 的 'opening line':

@Singleton
class MyActor @Inject()(cardViewRepository: CardViewRepository) extends Actor {
  //.. actor methods
}

有趣的是,它曾经可以正常工作,但突然抛出了这个异常。可能是因为我从 2.4.3 升级到 2.4.6?

@Salem 在评论中是正确的:"Probably the problem is with current as stated above. Try to inject Configuration in your MyRepository class and use in instead of current.configuration. If you really need the application object I think you can inject it instead... " 我需要在 MyRepository 中注入配置。