I am trying to start ktor using application.yaml
.
If I try to start it using an embedded server like below, it starts listening on the port defined for the embedded server as expected.
fun main() {
embeddedServer(Netty, port = 8080, host = "localhost", module = Application::main)
.start(wait = true)
}
fun Application.main() {
install(Koin) {
slf4jLogger()
modules(myModule)
}
configureRouting()
}
But if I change my main
to:
fun main(args: Array<String>): Unit = EngineMain.main(args)
I expected ktor to read the port from src/resources/application.yaml
:
ktor:
deployment:
host: "localhost"
port: 8080
application:
modules:
- com.example.ApplicationKt.main
Instead, I get this error:
Neither port nor sslPort specified. Use command line options -port/-sslPort or configure connectors in application.conf
What am I doing wrong?
You need to include the io.ktor:ktor-server-config-yaml
module to make it work:
implementation("io.ktor:ktor-server-config-yaml")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With