ktor:https://ktor.io/
整合Ktor
并提供一些扩展函数,版本号前缀与ktor官方一致
JSON序列化使用SpringBoot的ObjectMapper,需要创建一个ObjectMapper的bean
引入
repositories {
maven("https://nexus.kuku.me/repository/maven-public/")
mavenCentral()
}
implementation("me.kuku:ktor-spring-boot-starter:2.3.12.0")
@Component
class KtorRouting {
fun Routing.ro() {
route("") {
get {
call.respond("Hello World")
}
}
}
}
@Component
class KtorModule {
fun Application.statusPage() {
install(StatusPages) {
exception<Throwable> { cause ->
call.respond(HttpStatusCode.InternalServerError, Result.failure(cause.message ?: "服务器内部错误", null))
}
}
}
}