diff --git a/samples/webflux-kotlin/src/main/kotlin/com/example/webflux/WebfluxApplication.kt b/samples/webflux-kotlin/src/main/kotlin/com/example/webflux/WebfluxApplication.kt index 28251c326..3fe24099f 100644 --- a/samples/webflux-kotlin/src/main/kotlin/com/example/webflux/WebfluxApplication.kt +++ b/samples/webflux-kotlin/src/main/kotlin/com/example/webflux/WebfluxApplication.kt @@ -7,8 +7,6 @@ import org.springframework.nativex.hint.NativeHint import org.springframework.nativex.hint.TypeAccess import org.springframework.nativex.hint.TypeHint -// Reflection entry required due to how Coroutines generates bytecode with an Object return type, see https://github.com/spring-projects/spring-framework/issues/21546 related issue -@TypeHint(types = [Bar::class], access = [ TypeAccess.DECLARED_CONSTRUCTORS, TypeAccess.DECLARED_METHODS ]) @SpringBootApplication class WebfluxApplication diff --git a/spring-aot/src/main/java/org/springframework/aot/context/bootstrap/generator/infrastructure/nativex/NativeConfigurationUtils.java b/spring-aot/src/main/java/org/springframework/aot/context/bootstrap/generator/infrastructure/nativex/NativeConfigurationUtils.java index 4792cc54d..015a61ae9 100644 --- a/spring-aot/src/main/java/org/springframework/aot/context/bootstrap/generator/infrastructure/nativex/NativeConfigurationUtils.java +++ b/spring-aot/src/main/java/org/springframework/aot/context/bootstrap/generator/infrastructure/nativex/NativeConfigurationUtils.java @@ -23,10 +23,13 @@ import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; import java.lang.reflect.WildcardType; +import java.util.Arrays; import java.util.Comparator; import java.util.Set; import java.util.TreeSet; +import org.springframework.core.KotlinDetector; + // TODO review - does spring core already do some of these things? /** @@ -56,8 +59,19 @@ public static Set> collectTypesInSignature(Field field) { */ public static Set> collectTypesInSignature(Method controllerMethod) { Set> collector = new TreeSet<>(Comparator.comparing(Class::getName)); - collectReferenceTypesUsed(controllerMethod.getGenericReturnType(), collector); - for (Type parameterType : controllerMethod.getGenericParameterTypes()) { + Type genericReturnType; + Type[] genericParameterTypes; + if (KotlinDetector.isSuspendingFunction(controllerMethod)) { + Type[] types = controllerMethod.getGenericParameterTypes(); + ParameterizedType continuation = (ParameterizedType) types[types.length - 1]; + genericReturnType = ((WildcardType) continuation.getActualTypeArguments()[0]).getLowerBounds()[0]; + genericParameterTypes = Arrays.copyOf(types, types.length - 1); + } else { + genericReturnType = controllerMethod.getGenericReturnType(); + genericParameterTypes = controllerMethod.getGenericParameterTypes(); + } + collectReferenceTypesUsed(genericReturnType, collector); + for (Type parameterType : genericParameterTypes) { collectReferenceTypesUsed(parameterType, collector); } return collector;