GH-420 Fix discovery of function type from class
Fix introspection over ScannedGenericBeanDefinition Resolves #420
This commit is contained in:
@@ -81,13 +81,16 @@ public final class FunctionTypeUtils {
|
||||
*/
|
||||
public static Method discoverFunctionalMethod(Class<?> pojoFunctionClass) {
|
||||
if (Supplier.class.isAssignableFrom(pojoFunctionClass)) {
|
||||
return Stream.of(ReflectionUtils.getDeclaredMethods(pojoFunctionClass)).filter(m -> m.getName().equals("get")).findFirst().get();
|
||||
return Stream.of(ReflectionUtils.getDeclaredMethods(pojoFunctionClass)).filter(m -> !m.isSynthetic()
|
||||
&& m.getName().equals("get")).findFirst().get();
|
||||
}
|
||||
else if (Consumer.class.isAssignableFrom(pojoFunctionClass) || BiConsumer.class.isAssignableFrom(pojoFunctionClass)) {
|
||||
return Stream.of(ReflectionUtils.getDeclaredMethods(pojoFunctionClass)).filter(m -> m.getName().equals("accept")).findFirst().get();
|
||||
return Stream.of(ReflectionUtils.getDeclaredMethods(pojoFunctionClass)).filter(m -> !m.isSynthetic()
|
||||
&& m.getName().equals("accept")).findFirst().get();
|
||||
}
|
||||
else if (Function.class.isAssignableFrom(pojoFunctionClass) || BiFunction.class.isAssignableFrom(pojoFunctionClass)) {
|
||||
return Stream.of(ReflectionUtils.getDeclaredMethods(pojoFunctionClass)).filter(m -> m.getName().equals("apply")).findFirst().get();
|
||||
return Stream.of(ReflectionUtils.getDeclaredMethods(pojoFunctionClass)).filter(m -> !m.isSynthetic()
|
||||
&& m.getName().equals("apply")).findFirst().get();
|
||||
}
|
||||
|
||||
List<Method> methods = new ArrayList<>();
|
||||
|
||||
@@ -28,7 +28,9 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.config.ConstructorArgumentValues;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.cloud.function.context.catalog.FunctionTypeUtils;
|
||||
import org.springframework.cloud.function.core.FunctionFactoryMetadata;
|
||||
import org.springframework.context.annotation.ScannedGenericBeanDefinition;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.type.MethodMetadata;
|
||||
@@ -58,6 +60,15 @@ public abstract class FunctionContextUtils {
|
||||
if (definition == null) {
|
||||
return null;
|
||||
}
|
||||
else if (definition instanceof ScannedGenericBeanDefinition) {
|
||||
try {
|
||||
return FunctionTypeUtils.discoverFunctionTypeFromClass(definition.getBeanClass());
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore since name may not be actually resolved to a class in some cases
|
||||
// java.lang.IllegalStateException: Bean class name [functions.Greeter] has not been resolved into an actual Class
|
||||
}
|
||||
}
|
||||
|
||||
Object source = definition.getSource();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user