gpt4 book ai didi

spring-boot - 在spring-boot中使用kotlin暂停功能创建名称为 'requestMappingHandlerMapping'的bean时出错

转载 作者:行者123 更新时间:2023-12-02 13:30:52 26 4
gpt4 key购买 nike

spring-boot版本:2.2.6.RELEASE

kotlin版本:1.3.71

Kotlin协程版本:1.3.5

我正在尝试在Spring Boot的 Controller 中使用暂停功能。 Here是显示示例的官方文档。

@RestController
@RequestMapping("/account/v1")
class UserAccountResourceV1 {
@GetMapping("/username-taken", produces = [MediaType.TEXT_PLAIN_VALUE])
suspend fun userNameTaken(): String {
return "yes"
}
}

我在build.gradle.kts中添加了必需的依赖项:
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-jersey")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
developmentOnly("org.springframework.boot:spring-boot-devtools")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
implementation(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = "1.3.2")
}


它在运行时中断并抛出以下错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Unsupported suspending handler method detected: public java.lang.Object com.example.user.service.resources.UserAccountResourceV1.userNameTaken(kotlin.coroutines.Continuation)

完整的stderr是 here

需要一些帮助来弄清楚我的实现存在什么问题。

最佳答案

找出解决方案。

implementation("org.springframework.boot:spring-boot-starter-web")

需要替换为
implementation("org.springframework.boot:spring-boot-starter-webflux")

基本上 spring-boot-starter-webflux带来了对暂停功能的支持。

关于spring-boot - 在spring-boot中使用kotlin暂停功能创建名称为 'requestMappingHandlerMapping'的bean时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61381727/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com