11/*
2- * Copyright 2002-2018 the original author or authors.
2+ * Copyright 2002-2017 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -787,11 +787,12 @@ protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition m
787787 @ Override
788788 protected Class <?> getTypeForFactoryBean (String beanName , RootBeanDefinition mbd ) {
789789 String factoryBeanName = mbd .getFactoryBeanName ();
790- final String factoryMethodName = mbd .getFactoryMethodName ();
790+ String factoryMethodName = mbd .getFactoryMethodName ();
791791
792792 if (factoryBeanName != null ) {
793793 if (factoryMethodName != null ) {
794- // Try to obtain the FactoryBean's object type without instantiating it at all.
794+ // Try to obtain the FactoryBean's object type from its factory method declaration
795+ // without instantiating the containing bean at all.
795796 BeanDefinition fbDef = getBeanDefinition (factoryBeanName );
796797 if (fbDef instanceof AbstractBeanDefinition ) {
797798 AbstractBeanDefinition afbDef = (AbstractBeanDefinition ) fbDef ;
@@ -811,6 +812,7 @@ protected Class<?> getTypeForFactoryBean(String beanName, RootBeanDefinition mbd
811812 }
812813 }
813814
815+ // Let's obtain a shortcut instance for an early getObjectType() call...
814816 FactoryBean <?> fb = (mbd .isSingleton () ?
815817 getSingletonFactoryBeanForTypeCheck (beanName , mbd ) :
816818 getNonSingletonFactoryBeanForTypeCheck (beanName , mbd ));
@@ -849,12 +851,13 @@ protected Class<?> getTypeForFactoryBean(String beanName, RootBeanDefinition mbd
849851 * @param factoryMethodName the name of the factory method
850852 * @return the common {@code FactoryBean} object type, or {@code null} if none
851853 */
852- private Class <?> getTypeForFactoryBeanFromMethod (Class <?> beanClass , String factoryMethodName ) {
854+ private Class <?> getTypeForFactoryBeanFromMethod (Class <?> beanClass , final String factoryMethodName ) {
853855 class Holder { Class <?> value = null ; }
854856 final Holder objectType = new Holder ();
855857
856858 // CGLIB subclass methods hide generic parameters; look at the original user class.
857859 Class <?> fbClass = ClassUtils .getUserClass (beanClass );
860+
858861 // Find the given factory method, taking into account that in the case of
859862 // @Bean methods, there may be parameters present.
860863 ReflectionUtils .doWithMethods (fbClass ,
@@ -871,6 +874,7 @@ public void doWith(Method method) {
871874 }
872875 }
873876 });
877+
874878 return (objectType .value != null && Object .class != objectType .value ? objectType .value : null );
875879 }
876880
@@ -921,6 +925,7 @@ private FactoryBean<?> getSingletonFactoryBeanForTypeCheck(String beanName, Root
921925 (mbd .getFactoryBeanName () != null && isSingletonCurrentlyInCreation (mbd .getFactoryBeanName ()))) {
922926 return null ;
923927 }
928+
924929 Object instance = null ;
925930 try {
926931 // Mark this bean as currently in creation, even if just partially.
@@ -936,6 +941,7 @@ private FactoryBean<?> getSingletonFactoryBeanForTypeCheck(String beanName, Root
936941 // Finished partial creation of this bean.
937942 afterSingletonCreation (beanName );
938943 }
944+
939945 FactoryBean <?> fb = getFactoryBean (beanName , instance );
940946 if (bw != null ) {
941947 this .factoryBeanInstanceCache .put (beanName , bw );
@@ -956,6 +962,7 @@ private FactoryBean<?> getNonSingletonFactoryBeanForTypeCheck(String beanName, R
956962 if (isPrototypeCurrentlyInCreation (beanName )) {
957963 return null ;
958964 }
965+
959966 Object instance = null ;
960967 try {
961968 // Mark this bean as currently in creation, even if just partially.
@@ -979,6 +986,7 @@ private FactoryBean<?> getNonSingletonFactoryBeanForTypeCheck(String beanName, R
979986 // Finished partial creation of this bean.
980987 afterPrototypeCreation (beanName );
981988 }
989+
982990 return getFactoryBean (beanName , instance );
983991 }
984992
0 commit comments