Scala Play Guice依赖注入失败

问题描述 投票:1回答:1

我正在尝试使用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,所以我不确定为什么会出现这个错误。

任何帮助将不胜感激,我正在使用游戏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 := {}```


scala playframework playframework-2.0 guice
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.