diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java index 45195b9be8..0165c694f1 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/AbstractMethodAnnotationPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -196,15 +196,6 @@ public abstract class AbstractMethodAnnotationPostProcessor annotations, MessageHandler handler) { if (handler instanceof AbstractMessageProducingHandler || handler instanceof AbstractMessageRouter) { String sendTimeout = MessagingAnnotationUtils.resolveAttribute(annotations, "sendTimeout", String.class); @@ -611,7 +602,7 @@ public abstract class AbstractMethodAnnotationPostProcessor buildLambdaMessageProcessorForBeanMethod(Method method, Object target) { if ((target instanceof Function || target instanceof Consumer) && ClassUtils.isLambda(target.getClass()) - || ClassUtils.isKotlinFaction1(target.getClass())) { + || ClassUtils.isKotlinFunction1(target.getClass())) { ResolvableType methodReturnType = ResolvableType.forMethodReturnType(method); Class expectedPayloadType = methodReturnType.getGeneric(0).toClass(); @@ -622,6 +613,15 @@ public abstract class AbstractMethodAnnotationPostProcessor targetClass = target.getClass(); Assert.isTrue(MessageSource.class.isAssignableFrom(targetClass) || Supplier.class.isAssignableFrom(targetClass) || - ClassUtils.isKotlinFaction0(targetClass), + ClassUtils.isKotlinFunction0(targetClass), () -> "The '" + this.annotationType + "' on @Bean method " + "level is allowed only for: " + - MessageSource.class.getName() + " or " + Supplier.class.getName() + + MessageSource.class.getName() + ", or " + Supplier.class.getName() + (ClassUtils.KOTLIN_FUNCTION_0_CLASS != null - ? " or " + ClassUtils.KOTLIN_FUNCTION_0_CLASS.getName() + ? ", or " + ClassUtils.KOTLIN_FUNCTION_0_CLASS.getName() : "") + " beans"); if (target instanceof MessageSource) { messageSource = (MessageSource) target; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/ClassUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/util/ClassUtils.java index 974aff9eaa..433d9cb7c7 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/ClassUtils.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/ClassUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -250,21 +250,46 @@ public abstract class ClassUtils { * @param aClass the {@link Class} to check. * @return true if class is a {@code kotlin.jvm.functions.Function0} implementation. * @since 5.2 + * @deprecated since 5.5.14 in favor of {@link #isKotlinFunction0(Class)} */ + @Deprecated public static boolean isKotlinFaction0(Class aClass) { return KOTLIN_FUNCTION_0_CLASS != null && KOTLIN_FUNCTION_0_CLASS.isAssignableFrom(aClass); } + /** + * Check if class is {@code kotlin.jvm.functions.Function0}. + * @param aClass the {@link Class} to check. + * @return true if class is a {@code kotlin.jvm.functions.Function0} implementation. + * @since 5.5.14 + */ + public static boolean isKotlinFunction0(Class aClass) { + return KOTLIN_FUNCTION_0_CLASS != null && KOTLIN_FUNCTION_0_CLASS.isAssignableFrom(aClass); + } + /** * Check if class is {@code kotlin.jvm.functions.Function1}. * @param aClass the {@link Class} to check. * @return true if class is a {@code kotlin.jvm.functions.Function1} implementation. * @since 5.2 + * @deprecated since 5.5.14 in favor of {@link #isKotlinFunction1(Class)} */ + @Deprecated public static boolean isKotlinFaction1(Class aClass) { return KOTLIN_FUNCTION_1_CLASS != null && KOTLIN_FUNCTION_1_CLASS.isAssignableFrom(aClass); } + /** + * Check if class is {@code kotlin.jvm.functions.Function1}. + * @param aClass the {@link Class} to check. + * @return true if class is a {@code kotlin.jvm.functions.Function1} implementation. + * @since 5.5.14 + */ + public static boolean isKotlinFunction1(Class aClass) { + return KOTLIN_FUNCTION_1_CLASS != null && KOTLIN_FUNCTION_1_CLASS.isAssignableFrom(aClass); + } + + /** * Check if class is {@code kotlin.Unit}. * @param aClass the {@link Class} to check.