Shumilin Alexandr
11/14/2022, 1:15 PM@SpringBootApplication
class ApiApplication {
fun main(args: Array<String>) {
runApplication<ApiApplication>(*args) {
setBannerMode(Banner.Mode.OFF)
}
}
}
and this work! why?
@SpringBootApplication
class ApiApplication {
companion object {
@JvmStatic
fun main(args: Array<String>) {
SpringApplication.run(ApiApplication::class.java, *args)
}
}
}
Klitos Kyriacou
11/14/2022, 1:23 PMmain
is not one of the ways to specify an entry point in Kotlin. As you have it, it's just an ordinary instance function of the class. You can fix it by moving it out of the class:
@SpringBootApplication
class ApiApplication
fun main(args: Array<String>) {
runApplication<ApiApplication>(*args) {
setBannerMode(Banner.Mode.OFF)
}
}
Shumilin Alexandr
11/14/2022, 1:27 PMShumilin Alexandr
11/14/2022, 1:27 PMShumilin Alexandr
11/14/2022, 1:27 PMVishnu Ravi
11/14/2022, 6:21 PMpublic
and static
keyword as part of the main method signature. Your second example example get translated to this because of that companion object and static annotation, and that's why it worked.
In case of Kotlin, the entry point is a top level function (without enclosing that inside a class). And like @Klitos Kyriacou said, when you wrap it inside a class, it becomes an ordinary instance method.
Also, runApplication<ApiApplication>(*args)
is just a Kotlin idiomatic alternative to SpringApplication.run(ApiApplication::class.java, *args)