@@ -774,11 +774,12 @@ protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition m
774774 @ Override
775775 protected Class <?> getTypeForFactoryBean (String beanName , RootBeanDefinition mbd ) {
776776 String factoryBeanName = mbd .getFactoryBeanName ();
777- final String factoryMethodName = mbd .getFactoryMethodName ();
777+ String factoryMethodName = mbd .getFactoryMethodName ();
778778
779779 if (factoryBeanName != null ) {
780780 if (factoryMethodName != null ) {
781- // Try to obtain the FactoryBean's object type without instantiating it at all.
781+ // Try to obtain the FactoryBean's object type from its factory method declaration
782+ // without instantiating the containing bean at all.
782783 BeanDefinition fbDef = getBeanDefinition (factoryBeanName );
783784 if (fbDef instanceof AbstractBeanDefinition ) {
784785 AbstractBeanDefinition afbDef = (AbstractBeanDefinition ) fbDef ;
@@ -798,6 +799,7 @@ protected Class<?> getTypeForFactoryBean(String beanName, RootBeanDefinition mbd
798799 }
799800 }
800801
802+ // Let's obtain a shortcut instance for an early getObjectType() call...
801803 FactoryBean <?> fb = (mbd .isSingleton () ?
802804 getSingletonFactoryBeanForTypeCheck (beanName , mbd ) :
803805 getNonSingletonFactoryBeanForTypeCheck (beanName , mbd ));
@@ -842,6 +844,7 @@ class Holder { Class<?> value = null; }
842844
843845 // CGLIB subclass methods hide generic parameters; look at the original user class.
844846 Class <?> fbClass = ClassUtils .getUserClass (beanClass );
847+
845848 // Find the given factory method, taking into account that in the case of
846849 // @Bean methods, there may be parameters present.
847850 ReflectionUtils .doWithMethods (fbClass ,
@@ -858,6 +861,7 @@ public void doWith(Method method) {
858861 }
859862 }
860863 });
864+
861865 return (objectType .value != null && Object .class != objectType .value ? objectType .value : null );
862866 }
863867
@@ -908,6 +912,7 @@ private FactoryBean<?> getSingletonFactoryBeanForTypeCheck(String beanName, Root
908912 (mbd .getFactoryBeanName () != null && isSingletonCurrentlyInCreation (mbd .getFactoryBeanName ()))) {
909913 return null ;
910914 }
915+
911916 Object instance = null ;
912917 try {
913918 // Mark this bean as currently in creation, even if just partially.
@@ -923,6 +928,7 @@ private FactoryBean<?> getSingletonFactoryBeanForTypeCheck(String beanName, Root
923928 // Finished partial creation of this bean.
924929 afterSingletonCreation (beanName );
925930 }
931+
926932 FactoryBean <?> fb = getFactoryBean (beanName , instance );
927933 if (bw != null ) {
928934 this .factoryBeanInstanceCache .put (beanName , bw );
@@ -943,6 +949,7 @@ private FactoryBean<?> getNonSingletonFactoryBeanForTypeCheck(String beanName, R
943949 if (isPrototypeCurrentlyInCreation (beanName )) {
944950 return null ;
945951 }
952+
946953 Object instance = null ;
947954 try {
948955 // Mark this bean as currently in creation, even if just partially.
@@ -966,6 +973,7 @@ private FactoryBean<?> getNonSingletonFactoryBeanForTypeCheck(String beanName, R
966973 // Finished partial creation of this bean.
967974 afterPrototypeCreation (beanName );
968975 }
976+
969977 return getFactoryBean (beanName , instance );
970978 }
971979
0 commit comments