更新Maven源
vim ~/.gradle/init.gradle
allprojects {
repositories {
maven {
url "http://maven.aliyun.com/nexus/content/groups/public"
}
}
}
SpringBoot+Kotlin
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk version
# SDKMAN 5.6.2+294
sdk install springboot 2.0.6.RELEASE
sdk use springboot 2.0.6.RELEASE
spring version
# Spring CLI v2.0.6.RELEASE
关于SDKMAN更多介绍 可以参考SDKMAN
spring init -a demo -b 2.0.6.RELEASE --build gradle -dweb -l kotlin KotlinBasic
cd KotlinBasic
关于更多springboot命令行工具参数 可以参考"spring help init"
./gradlew bootrun
如果发生"Kotlin home does not exist or is not a directory"错误 可以参考Error while compiling the kotlin program in IDEA
Controller
vim src/main/kotlin/com/example/demo/DemoController.kt
package com.example.demo
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController
@RestController
class DemoController {
@GetMapping("/demo")
fun demo(): String {
return "demo"
}
}
./gradlew bootrun
curl localhost:8080/demo # demo