1

I've created a Kotlin gradle project using Spring IO.

Created a Controller class with a method to return a String.

When I build and run the project I'm getting 404 error. Looking at the logs I don't see the URL mapping to the method.

If I use Java instead of Kotlin it works fine. I am using JDK 10.

Code

@RestController
class IslandController

@GetMapping("/greeting")
fun getMessage() =

        "hello world"
Akhil Jain
  • 13,872
  • 15
  • 57
  • 93

1 Answers1

6

You have to include your function into the controller class:

@RestController
class IslandController {

    @GetMapping("/greeting")
    fun getMessage() = "hello world"
}
Cepr0
  • 28,144
  • 8
  • 75
  • 101
  • curly braces are optional in Kotlin – chattambigeek Jun 26 '18 at 10:34
  • 1
    @chattambigeek from the [Kotlin reference documentation](https://kotlinlang.org/docs/reference/classes.html): _"if the class **has no body**, curly braces can be omitted."_ – Viç Jun 26 '18 at 10:43