Scala Play Guice依赖注入失败

时间:2019-03-26 10:54:58

标签: scala playframework playframework-2.0 guice

我正在尝试使用Guice作为DI在Scala中构建一个播放应用程序。在执行sbt run时,该应用程序似乎运行良好,但是在运行得到的jar时;

Oops, cannot start the server.
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.
at scala.sys.package$.error(package.scala:30)
at play.api.ApplicationLoader$.play$api$ApplicationLoader$$loaderNotFound(ApplicationLoader.scala:48)
at play.api.ApplicationLoader$.apply(ApplicationLoader.scala:143)
at play.core.server.ProdServerStart$.start(ProdServerStart.scala:56)
at play.core.server.ProdServerStart$.main(ProdServerStart.scala:29)
at play.core.server.ProdServerStart.main(ProdServerStart.scala)

我的build.sbt中有libraryDependencies += guice,所以我不确定为什么会收到此错误。

任何帮助,我正在使用play 2.7。

Build.sbt文件:

name := "my-project"
organization := "com.mycompany"

version := "1.0.0"

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

scalaVersion := "2.12.8"

libraryDependencies += guice
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "4.0.1" % Test
libraryDependencies += "commons-codec" % "commons-codec" % "1.12"
libraryDependencies += "org.javaswift" % "joss" % "0.10.2"
libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.2.3"
libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.2"
libraryDependencies += "com.amazonaws" % "aws-java-sdk-s3" % "1.11.519"
libraryDependencies += "com.softwaremill.macwire" %% "macros" % "2.3.1" % "provided"
libraryDependencies += "com.softwaremill.macwire" %% "util" % "2.3.1"

// Adds additional packages into Twirl
//TwirlKeys.templateImports += "com.realitymine.controllers._"

// Adds additional packages into conf/routes
// play.sbt.routes.RoutesKeys.routesImport += "com.realitymine.binders._"

mainClass in assembly := Some("play.core.server.ProdServerStart")
fullClasspath in assembly += Attributed.blank(PlayKeys.playPackageAssets.value)

assemblyMergeStrategy in assembly := {
  case manifest if manifest.contains("MANIFEST.MF") =>
    // We don't need manifest files since sbt-assembly will create
    // one with the given settings
    MergeStrategy.discard
  case referenceOverrides if referenceOverrides.contains("reference-overrides.conf") =>
    // Keep the content for all reference-overrides.conf files
    MergeStrategy.concat
//  case x =>
//    // For all the other files, use the default sbt-assembly merge strategy
//    val oldStrategy = (assemblyMergeStrategy in assembly).value
//    oldStrategy(x)
  case PathList("META-INF", xs @ _*) => MergeStrategy.discard
  case x => MergeStrategy.first
}

test in assembly := {}```


1 个答案:

答案 0 :(得分:1)

正如评论中提到的,我遇到了同样的问题,并在这里找到了解决方案。 Merge Strategy in sbt assembly and missing application loader