Spring @RestController is not mapping URL with Kotlin

1.3k Views Asked by At

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"
1

There are 1 best solutions below

2
On BEST ANSWER

You have to include your function into the controller class:

@RestController
class IslandController {

    @GetMapping("/greeting")
    fun getMessage() = "hello world"
}