简体   繁体   中英

Spring @RestController is not mapping URL with Kotlin

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"

You have to include your function into the controller class:

@RestController
class IslandController {

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM