Does spring boot jersey support coroutines? Follow...
# spring
s
Does spring boot jersey support coroutines? Following code is giving me this error:
Copy code
WARNING: A HTTP GET method, public final java.lang.Object com.example.demo.FooController.bar(java.lang.String,kotlin.coroutines.Continuation), should not consume any entity.
WARNING: Parameter 1 of type kotlin.coroutines.Continuation<? super java.lang.String> from public final java.lang.Object com.example.demo.FooController.foobar(kotlin.coroutines.Continuation<? super java.lang.String>) is not resolvable to a concrete type.
WARNING: A HTTP GET method, public final java.lang.Object com.example.demo.FooController.foobar(kotlin.coroutines.Continuation), should not consume any entity.

2021-01-10 11:51:30.715 ERROR 20636 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[.[.e.demo.JerseyConfig]   : Servlet.service() for servlet [com.example.demo.JerseyConfig] in context with path [] threw exception [java.lang.NullPointerException] with root cause

java.lang.NullPointerException: null
	at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:193) ~[kotlinx-coroutines-core-jvm-1.4.2.jar:na]
	at com.example.demo.FooController.bar(FooController.kt:36) ~[main/:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
Code:
Copy code
@GET
    @Path("{name}")
    @Produces(MediaType.APPLICATION_JSON)
    suspend fun bar(@PathParam("name") name: String): Bar = coroutineScope {
        val foo = async { Bar(name) }
        foo.await()
    }
w
i think to do coroutines on your resource classes you need to be on webflux (project reactor). outside of that, i think you need to not make your resource methods 
suspend
 and start a blocking coroutine context within the method
j
@wakingrufus this is no longer true - support for suspending functions was added to Spring MVC with Spring Boot 2.4
w
Oh awesome! TIL thanks!
b
huh, i don’t remember reading anything about that, and i can’t find it in release notes… any suggestions on where that was announced?