Я пытаюсь использовать spray-json
на akka-http
сервере, и я получаю эту ошибку:
Exception in thread "main" com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'spray'
И действительно, в моей конфигурации нет настройки spray
.Я просмотрел несколько документов, но до сих пор не могу найти, как и зачем устанавливать spray json
в конфигурации.Может быть, я делаю что-то не так.Я полностью потерян и застрял, пожалуйста, помогите.
Это мой buid.sbt :
enablePlugins(JavaServerAppPackaging)
name := "api-server"
version := "0.1"
scalaVersion := "2.12.8"
val akkaVersion = "2.5.21"
val akkaHttpVersion = "10.1.7"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-http-core" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-slf4j" % akkaVersion,
"ch.qos.logback" % "logback-classic" % "1.2.3"
)
// Assembly settings
mainClass in assembly := Some("company.Main")
assemblyJarName in assembly := "company.jar"
Это мой plugins.sbt
resolvers += Classpaths.typesafeReleases
addSbtPlugin("com.eed3si9n" %% "sbt-assembly" % "0.14.9")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.19")
Спасибо.
////////// ДОБАВЛЕНО /////////////////
Полныйтрассировка стека:
Exception in thread "main" com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'spray'
at com.typesafe.config.impl.SimpleConfig.findKeyOrNull(SimpleConfig.java:156)
at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:149)
at com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:176)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:188)
at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:193)
at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:250)
at com.epoqee.gotickets.RequestTimeout.requestTimeout(Main.scala:39)
at com.epoqee.gotickets.RequestTimeout.requestTimeout$(Main.scala:38)
at com.epoqee.gotickets.Main$.requestTimeout(Main.scala:13)
at com.epoqee.gotickets.Main$.delayedEndpoint$com$epoqee$gotickets$Main$1(Main.scala:21)
at com.epoqee.gotickets.Main$delayedInit$body.apply(Main.scala:13)
at scala.Function0.apply$mcV$sp(Function0.scala:39)
at scala.Function0.apply$mcV$sp$(Function0.scala:39)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
at scala.App.$anonfun$main$1$adapted(App.scala:80)
at scala.collection.immutable.List.foreach(List.scala:392)
at scala.App.main(App.scala:80)
at scala.App.main$(App.scala:78)
at company.Main$.main(Main.scala:13)
at company.Main.main(Main.scala)
Кроме того, вот как я интегрирую spray json
в проект:
package company
import spray.json._
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
trait EventMarshalling extends SprayJsonSupport with DefaultJsonProtocol {
implicit val eventFormat = jsonFormat1(Event)
...
}
/////////// ДОБАВЛЕНО ////////////////// Main.scala
package com.epoqee.gotickets
import scala.concurrent.Future
import akka.actor.ActorSystem
import akka.event.Logging
import akka.util.Timeout
import akka.http.scaladsl.Http
import akka.http.scaladsl.Http.ServerBinding
import akka.stream.ActorMaterializer
import com.typesafe.config.{Config, ConfigFactory}
object Main extends App with RequestTimeout {
val config = ConfigFactory.load()
val host = config.getString("http.host")
val port = config.getInt("http.port")
implicit val system = ActorSystem()
implicit val ec = system.dispatcher
val api = new RestApi(system, requestTimeout(config)).routes
implicit val materializer = ActorMaterializer()
val bindingFuture: Future[ServerBinding] = Http().bindAndHandle(api, host, port)
val log = Logging(system.eventStream, "go-ticks")
bindingFuture.map { serverBinding =>
log.info(s"RestApi bound to ${serverBinding.localAddress} ")
}.onFailure {
case ex: Exception =>
log.error(ex, "Failed to bind to {}:{}!", host, port)
system.terminate()
}
}
trait RequestTimeout {
import scala.concurrent.duration._
def requestTimeout(config: Config): Timeout = {
val t = config.getString("spray.can.server.request-timeout")
val d = Duration(t)
FiniteDuration(d.length, d.unit)
}
}