gpt4 book ai didi

kotlin - Ktor - 使用协程发布未处理的错误

转载 作者:行者123 更新时间:2023-12-03 16:10:03 28 4
gpt4 key购买 nike

我是 Kotlin 和 Ktor 的新手,所以我尝试做简单的发布请求。正如你在下面看到的,没有什么特别的。

    routing {
post("/articles/add"){
val post = call.receive<ArticleRequest>()
println(post)
}
日志中显示的错误如下,我不明白为什么我应该在这里使用协程。
ERROR Application - Unhandled: POST - /articles/add 
java.lang.IllegalStateException: Using blocking primitives on this dispatcher is not allowed. Consider using async channel instead or use blocking primitives in withContext(Dispatchers.IO) instead.
我正在使用 1.4.2 版本。我将不胜感激任何帮助。

最佳答案

如果您使用的是 Jackson,这是一个 bug并且有一个建议的解决方法:

routing {
post("/articles/add") {
with(Dispatchers.IO) {
val post = call.receive<ArticleRequest>()
println(post)
}
}
}
或者您可以回滚到 1.4.1,直到错误解决。

关于kotlin - Ktor - 使用协程发布未处理的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64903270/

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