繁体   English   中英

Scala Play Guice 依赖注入失败

[英]Scala Play Guice Dependency Injection Fails

我正在尝试使用 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)

我的libraryDependencies += guicelibraryDependencies += 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 := {}```


正如评论中提到的,我遇到了同样的问题,并在这里找到了解决方案。 sbt 程序集中的合并策略和缺少应用程序加载程序

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM