diff --git a/spring-core/src/main/java/org/springframework/core/KotlinDetector.java b/spring-core/src/main/java/org/springframework/core/KotlinDetector.java index fde4e10a6c..b7bb1de0d3 100644 --- a/spring-core/src/main/java/org/springframework/core/KotlinDetector.java +++ b/spring-core/src/main/java/org/springframework/core/KotlinDetector.java @@ -19,6 +19,8 @@ package org.springframework.core; import java.lang.annotation.Annotation; import java.lang.reflect.Method; +import kotlin.reflect.jvm.ReflectJvmMapping; + import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; @@ -93,4 +95,15 @@ public abstract class KotlinDetector { return false; } + /** + * Return {@code true} if the method is a kotlin function. + * @since 6.1.3 + */ + public static boolean isKotlinFunction(Method method) { + if (KotlinDetector.isKotlinType(method.getDeclaringClass())) { + return ReflectJvmMapping.getKotlinFunction(method) != null; + } + return false; + } + } diff --git a/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java b/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java index 2b5b0e8c57..5f5e3916d6 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/InvocableHandlerMethod.java @@ -255,7 +255,7 @@ public class InvocableHandlerMethod extends HandlerMethod { if (KotlinDetector.isSuspendingFunction(method)) { return invokeSuspendingFunction(method, getBean(), args); } - else if (KotlinDetector.isKotlinType(method.getDeclaringClass())) { + else if (KotlinDetector.isKotlinFunction(method)) { return KotlinDelegate.invokeFunction(method, getBean(), args); } }