Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start ktor using application.yaml

Tags:

kotlin

ktor

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?

like image 679
alturkovic Avatar asked Sep 18 '25 20:09

alturkovic


1 Answers

You need to include the io.ktor:ktor-server-config-yaml module to make it work:

implementation("io.ktor:ktor-server-config-yaml")
like image 161
Aleksei Tirman Avatar answered Sep 22 '25 16:09

Aleksei Tirman