Support suspending handler methods in Spring MVC
This commit adds support for Kotlin Coroutines suspending functions to Spring MVC, by converting those to a Mono that can then be handled by the asynchronous request processing feature. It also optimizes Coroutines detection with the introduction of an optimized KotlinDetector.isSuspendingFunction() method that does not require kotlin-reflect. Closes gh-23611
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.core;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -74,4 +75,20 @@ public abstract class KotlinDetector {
|
||||
return (kotlinMetadata != null && clazz.getDeclaredAnnotation(kotlinMetadata) != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@code true} if the method is a suspending function.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.3
|
||||
*/
|
||||
public static boolean isSuspendingFunction(Method method) {
|
||||
if (KotlinDetector.isKotlinType(method.getDeclaringClass())) {
|
||||
Class<?>[] types = method.getParameterTypes();
|
||||
if ((types.length > 0) && "kotlin.coroutines.Continuation".equals(types[types.length - 1].getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user