diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java index 9949f4a01b34..34174b1b3797 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.KotlinDetector; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.ServerCodecConfigurer; @@ -328,7 +329,8 @@ public Mono handleError(ServerWebExchange exchange, Throwable ex) /** - * Match methods with a return type without an adapter in {@link ReactiveAdapterRegistry}. + * Match methods with a return type without an adapter in {@link ReactiveAdapterRegistry} + * which are not suspending functions. */ private record NonReactiveHandlerMethodPredicate(ReactiveAdapterRegistry adapterRegistry) implements Predicate { @@ -336,7 +338,8 @@ private record NonReactiveHandlerMethodPredicate(ReactiveAdapterRegistry adapter @Override public boolean test(HandlerMethod handlerMethod) { Class returnType = handlerMethod.getReturnType().getParameterType(); - return (this.adapterRegistry.getAdapter(returnType) == null); + return (this.adapterRegistry.getAdapter(returnType) == null + && !KotlinDetector.isSuspendingFunction(handlerMethod.getMethod())); } }