使用 application.yaml 启动 ktor

alt*_*vic 3 kotlin ktor

我正在尝试使用 启动 ktor application.yaml

如果我尝试使用如下所示的嵌入式服务器启动它,它会按预期开始侦听为嵌入式服务器定义的端口。

fun main() {
    embeddedServer(Netty, port = 8080, host = "localhost", module = Application::main)
        .start(wait = true)
}

fun Application.main() {
    install(Koin) {
        slf4jLogger()
        modules(myModule)
    }
    configureRouting()
}
Run Code Online (Sandbox Code Playgroud)

但如果我将我的更改main为:

fun main(args: Array<String>): Unit = EngineMain.main(args)
Run Code Online (Sandbox Code Playgroud)

我希望 ktor 从以下位置读取端口src/resources/application.yaml

ktor:
  deployment:
    host: "localhost"
    port: 8080
  application:
    modules:
      - com.example.ApplicationKt.main
Run Code Online (Sandbox Code Playgroud)

相反,我收到此错误:

Neither port nor sslPort specified. Use command line options -port/-sslPort or configure connectors in application.conf
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Ale*_*man 6

您需要包含该io.ktor:ktor-server-config-yaml模块才能使其工作:

implementation("io.ktor:ktor-server-config-yaml")
Run Code Online (Sandbox Code Playgroud)