https://github.com/kukume/ktor-spring-boot-starter
ktor-spring-boot-starter
https://github.com/kukume/ktor-spring-boot-starter
kotlin ktor ktor-server spring-boot spring-boot-starter
Last synced: 5 months ago
JSON representation
ktor-spring-boot-starter
- Host: GitHub
- URL: https://github.com/kukume/ktor-spring-boot-starter
- Owner: kukume
- License: mit
- Created: 2022-03-24T15:14:39.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-07-10T12:41:04.000Z (almost 2 years ago)
- Last Synced: 2025-05-22T22:05:40.726Z (about 1 year ago)
- Topics: kotlin, ktor, ktor-server, spring-boot, spring-boot-starter
- Language: Kotlin
- Homepage:
- Size: 94.7 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## ktor-spring-boot-starter
ktor:https://ktor.io/
整合`Ktor`并提供一些扩展函数,版本号前缀与ktor官方一致
JSON序列化使用SpringBoot的ObjectMapper,需要创建一个ObjectMapper的bean
### 使用
#### 引入(gradle.kts)
引入
```kotlin
repositories {
maven("https://nexus.kuku.me/repository/maven-public/")
mavenCentral()
}
implementation("me.kuku:ktor-spring-boot-starter:2.3.12.0")
```
#### Routing
```kotlin
@Component
class KtorRouting {
fun Routing.ro() {
route("") {
get {
call.respond("Hello World")
}
}
}
}
```
#### Module(异常处理)
```kotlin
@Component
class KtorModule {
fun Application.statusPage() {
install(StatusPages) {
exception { cause ->
call.respond(HttpStatusCode.InternalServerError, Result.failure(cause.message ?: "服务器内部错误", null))
}
}
}
}
```