[英]Spring @RestController is not mapping URL with Kotlin
I've created a Kotlin gradle project using Spring IO . 我已经使用Spring IO创建了一个Kotlin gradle项目。
Created a Controller
class with a method to return a String
. 创建了一个带有返回
String
的方法的Controller
类。
When I build and run the project I'm getting 404 error. 当我构建并运行项目时,出现404错误。 Looking at the logs I don't see the URL mapping to the method.
查看日志,我看不到该方法的URL映射。
If I use Java instead of Kotlin it works fine. 如果我使用Java而不是Kotlin,则效果很好。 I am using JDK 10.
我正在使用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"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.