从泛型类中的Kotlin协程调用Spring Reactive WebClient方法awaitBody

问题描述

在尝试在Kotlin中使用协程时,我在一段代码上苦苦挣扎。我正在从通用类中调用Spring的reactive.function.client方法awaitBody(),并且遇到错误

Kotlin: Cannot use 'Response' as reified type parameter. Use a class instead.

呼叫代码

class ReactiveWebClient<Request: Any,Response: Any> {
    suspend fun post(uri: URI,request: Request,headers: (HttpHeaders) -> Unit): Response {
        return webClient.post()
            .uri(uri)
            .body(BodyInserters.fromValue(request))
            .headers(headers)
            .retrieve()
            .awaitBody()  // error on this line
    }
}

awaitBody的签名:

public suspend inline fun <reified T : kotlin.Any> org.springframework.web.reactive.function.client.WebClient.ResponseSpec.awaitBody(): T { /* compiled code */ }

可以找到整个课程here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)