Hey all, I was testing Spring Webflux with corouti...
# spring
a
Hey all, I was testing Spring Webflux with coroutines and had the following code
Copy code
@RestController
class Controller {
    @GetMapping("/hello")
    suspend fun delayedHelloWorld(
        @RequestParam timeout: Int,
    ): String {
		println("Delaying for $timeout")
    	delay(timeout.toLong())
        return "Hello World!"
    }
}

@SpringBootApplication
class DemoApplication

fun main(args: Array<String>) {
	runApplication<DemoApplication>(*args)
}
Using only the following gradle dependencies:
Copy code
org.springframework.boot:spring-boot-starter-webflux:3.3.1
org.jetbrains.kotlinx:kotlinx-coroutines-reactor:1.8.1
And when I execute
curl "<http://localhost:8080/hello?timeout=10000>"
I get the following exception
Copy code
java.lang.NullPointerException: null
	at kotlin.coroutines.jvm.internal.ContinuationImpl.getContext(ContinuationImpl.kt:105)
	at kotlin.coroutines.jvm.internal.ContinuationImpl.intercepted(ContinuationImpl.kt:112)
	at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt.intercepted(IntrinsicsJvm.kt:182)
	at kotlinx.coroutines.DelayKt.delay(Delay.kt:172)
	at com.demo.Controller.delayedHelloWorld$suspendImpl(Spring.kt:17)
	at com.demo.Controller.delayedHelloWorld(Spring.kt)
	...
Any ideias why?
I used https://start.spring.io/ and selected only reactive with kotlin support and it looks like this is fixed by including
com.fasterxml.jackson.module:jackson-module-kotlin
which is oddly weird
Although from the Spring documents it is not mentioned https://docs.spring.io/spring-framework/reference/languages/kotlin/coroutines.html
Ah got it, its the kotlin-reflect module that was missing
Adding
org.jetbrains.kotlin:kotlin-reflect
does the job
👍 1
b
it's weird that a
ContinuationImpl
is depending on a reflect method not to fail
118 Views