我正在尝试将 akka-http 服务器嵌入到我的 ammonite scala 脚本中。
下面是用于创建服务器实例的 scala 代码
import ammonite.ops._
import $ivy.`com.typesafe:config:1.3.1`
import $ivy.`com.typesafe.akka:akka-http_2.12:10.0.6`
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Directives._
import com.typesafe.config.ConfigFactory
import java.io._
@main
def main() = {
val fileConfig = ConfigFactory.parseFile(new File("resources/my.conf"))
val config = ConfigFactory.load(fileConfig)
println(config)
implicit val actorSystem = ActorSystem("system")
implicit val actorMaterializer = ActorMaterializer()
val route =
pathSingleSlash {
get {
complete {
"Hello world"
}
}
}
Http().bindAndHandle(route,"localhost",8080)
println("server started at 8080")
}
这是my.conf
文件内容:
akka {
loglevel = INFO
stdout-loglevel = INFO
default-dispatcher {
fork-join-executor {
parallelism-min = 8
}
}
运行脚本时amm server.sc
出现以下错误:
Exception in thread "main" com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka'
application.conf
标准文件名约定也会发生同样的情况。
我可以读取文件并正确获取内容。我错过了什么?
非常感谢