List of usage examples for org.springframework.core GenericTypeResolver resolveReturnTypeArgument
@Nullable public static Class<?> resolveReturnTypeArgument(Method method, Class<?> genericIfc)
From source file:org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.java
/** * Introspect the factory method signatures on the given bean class, * trying to find a common {@code FactoryBean} object type declared there. * @param beanClass the bean class to find the factory method on * @param factoryMethodName the name of the factory method * @return the common {@code FactoryBean} object type, or {@code null} if none *//*w w w .ja v a2s .c om*/ @Nullable private Class<?> getTypeForFactoryBeanFromMethod(Class<?> beanClass, final String factoryMethodName) { /** * Holder used to keep a reference to a {@code Class} value. */ class Holder { @Nullable Class<?> value = null; } final Holder objectType = new Holder(); // CGLIB subclass methods hide generic parameters; look at the original user class. Class<?> fbClass = ClassUtils.getUserClass(beanClass); // Find the given factory method, taking into account that in the case of // @Bean methods, there may be parameters present. ReflectionUtils.doWithMethods(fbClass, method -> { if (method.getName().equals(factoryMethodName) && FactoryBean.class.isAssignableFrom(method.getReturnType())) { Class<?> currentType = GenericTypeResolver.resolveReturnTypeArgument(method, FactoryBean.class); if (currentType != null) { objectType.value = ClassUtils.determineCommonAncestor(currentType, objectType.value); } } }); return (objectType.value != null && Object.class != objectType.value ? objectType.value : null); }