Я пытаюсь использовать новую функцию Spring 5.2 - интеграцию с сопрограммами kotlin, но во время выполнения у меня всегда есть NPE.Это пример:
@RestController
class SomeController() {
val webClient = WebClient.builder()
.baseUrl("https://www.google.com")
.build()
@GetMapping
suspend fun get(): String? {
return webClient
.get()
.awaitExchange()
.awaitBody()
}
}
и NPE на .awaitExchange () :
kotlin.KotlinNullPointerException: null
at kotlin.coroutines.jvm.internal.ContinuationImpl.getContext(ContinuationImpl.kt:105) ~[kotlin-stdlib-1.3.40.jar:1.3.40-release-123 (1.3.40)]
at kotlin.coroutines.jvm.internal.ContinuationImpl.<init>(ContinuationImpl.kt:102) ~[kotlin-stdlib-1.3.40.jar:1.3.40-release-123 (1.3.40)]
at org.springframework.web.reactive.function.client.WebClientExtensionsKt$awaitExchange$1.<init>(WebClientExtensions.kt) ~[spring-webflux-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.web.reactive.function.client.WebClientExtensionsKt.awaitExchange(WebClientExtensions.kt) ~[spring-webflux-5.2.0.M3.jar:5.2.0.M3]
at com.test.SomeController.get$suspendImpl(SomeController.kt:22) ~[classes/:na]
at com.test.SomeController.get(SomeController.kt) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_171]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_171]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_171]
at org.springframework.web.reactive.result.method.InvocableHandlerMethod.lambda$invoke$0(InvocableHandlerMethod.java:146) ~[spring-webflux-5.2.0.M3.jar:5.2.0.M3]
at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:118) [reactor-core-3.3.0.M2.jar:3.3.0.M2]
at reactor.core.publisher.Operators$MonoSubscriber.complete(Operators.java:1575) ~[reactor-core-3.3.0.M2.jar:3.3.0.M2]
...
Есть идеи, что я делаю неправильно?
Ps gradle зависимости:
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = "1.2.2")
implementation(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-reactor", version = "1.2.2")
implementation(group = "org.springframework.boot", name = "spring-boot-starter-webflux", version = "2.2.0.M4")
}
Спасибо!