Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Kotlin Example of Class and Controller
data class Greeting(val id: Long, val content: String)
Next, a GreetingController will be used for a get request:
@RestController
class GreetingController {
val counter = AtomicLong()
@GetMapping("/greeting")
fun greeting(@RequestParam(value = "name", defaultValue = "World") name: String) =
Greeting(counter.incrementAndGet(), "Hello, $name")
}
When creating the Application class Spring Boot looks for a public static main method. This can be defined in Kotlin using a top-level function defined outside Application class like this:
@SpringBootApplication
class Application
fun main(args: Array<String>) {
SpringApplication.run(Application::class.java, *args)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment