【问题标题】:play framework in an sbt subproject - no applicaton loader defined在 sbt 子项目中播放框架 - 未定义应用程序加载器
【发布时间】:2020-01-20 15:12:04
【问题描述】:

我正在尝试创建一个播放框架项目作为 sbt 子项目。

作为最小配置,我创建了这个 build.sbt:

name := """api-skeleton"""
organization := "my.domain"

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).aggregate(api)
lazy val api = (project in file("api")).enablePlugins(PlayScala)

libraryDependencies += guice
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test

scalaVersion := "2.13.1"

运行sbt project api run 播放框架按预期启动,通知我它正在侦听端口 9000 并等待请求。向它发送请求将导致此错误消息:

java.lang.RuntimeException: No application loader is configured. Please configure an application loader either using the play.application.loader configuration property, or by depending on a module that configures one. You can add the Guice support module by adding "libraryDependencies += guice" to your build.sbt.
     scala.sys.package$.error(package.scala:30)
     play.api.ApplicationLoader$.play$api$ApplicationLoader$$loaderNotFound(ApplicationLoader.scala:51)
     play.api.ApplicationLoader$.apply(ApplicationLoader.scala:159)
     play.core.server.DevServerStart$$anon$1.$anonfun$reload$3(DevServerStart.scala:188)
     play.utils.Threads$.withContextClassLoader(Threads.scala:21)
     play.core.server.DevServerStart$$anon$1.reload(DevServerStart.scala:181)
     play.core.server.DevServerStart$$anon$1.get(DevServerStart.scala:141)
     play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:296)
     play.core.server.AkkaHttpServer.$anonfun$createServerBinding$1(AkkaHttpServer.scala:186)
     akka.stream.impl.fusing.MapAsync$$anon$30.onPush(Ops.scala:1261)
     akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:541)
     akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:423)
     akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:624)
     akka.stream.impl.fusing.GraphInterpreterShell$AsyncInput.execute(ActorGraphInterpreter.scala:501)
     akka.stream.impl.fusing.GraphInterpreterShell.processEvent(ActorGraphInterpreter.scala:599)
     akka.stream.impl.fusing.ActorGraphInterpreter.akka$stream$impl$fusing$ActorGraphInterpreter$$processEvent(ActorGraphInterpreter.scala:768)
     akka.stream.impl.fusing.ActorGraphInterpreter$$anonfun$receive$1.applyOrElse(ActorGraphInterpreter.scala:783)
     akka.actor.Actor.aroundReceive(Actor.scala:533)
     akka.actor.Actor.aroundReceive$(Actor.scala:531)
     akka.stream.impl.fusing.ActorGraphInterpreter.aroundReceive(ActorGraphInterpreter.scala:690)
     akka.actor.ActorCell.receiveMessage(ActorCell.scala:573)
     akka.actor.ActorCell.invoke(ActorCell.scala:543)
     akka.dispatch.Mailbox.processMailbox(Mailbox.scala:269)
     akka.dispatch.Mailbox.run(Mailbox.scala:230)
     akka.dispatch.Mailbox.exec(Mailbox.scala:242)
     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)

谷歌搜索这条消息(并阅读它)告诉我我需要在我的项目中添加 guice。我做了,因为它在 build.sbt 中可见。还有一些关于删除类似 StackQuestion 中的目标文件夹的事情,我也尝试过。

【问题讨论】:

    标签: playframework sbt guice


    【解决方案1】:

    我遇到的问题是由于 libraryDependencies 没有像我假设的那样用于所有项目。所以 guice 从未加载过,并且错误消息非常准确。

    为了为子项目加载 guice,我在我的项目目录中创建了一个名为 Dependencies.scala 的依赖文件。它看起来像这样:

    import sbt._
    import play.sbt.PlayImport._
    
    object Dependencies {
      val play: Seq[ModuleID] = Seq(
        guice
      )
    }
    

    我现在可以通过在我的build.sbt 中执行此操作来为我的子项目提供依赖项:

    lazy val api = project
      .enablePlugins(PlayScala)
      .settings(
        libraryDependencies ++= Dependencies.play
      )
    

    现在它可以工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-07
      • 2016-11-19
      • 2015-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-16
      相关资源
      最近更新 更多