@@ -774,11 +774,12 @@ protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition m
774
774
@ Override
775
775
protected Class <?> getTypeForFactoryBean (String beanName , RootBeanDefinition mbd ) {
776
776
String factoryBeanName = mbd .getFactoryBeanName ();
777
- final String factoryMethodName = mbd .getFactoryMethodName ();
777
+ String factoryMethodName = mbd .getFactoryMethodName ();
778
778
779
779
if (factoryBeanName != null ) {
780
780
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.
782
783
BeanDefinition fbDef = getBeanDefinition (factoryBeanName );
783
784
if (fbDef instanceof AbstractBeanDefinition ) {
784
785
AbstractBeanDefinition afbDef = (AbstractBeanDefinition ) fbDef ;
@@ -798,6 +799,7 @@ protected Class<?> getTypeForFactoryBean(String beanName, RootBeanDefinition mbd
798
799
}
799
800
}
800
801
802
+ // Let's obtain a shortcut instance for an early getObjectType() call...
801
803
FactoryBean <?> fb = (mbd .isSingleton () ?
802
804
getSingletonFactoryBeanForTypeCheck (beanName , mbd ) :
803
805
getNonSingletonFactoryBeanForTypeCheck (beanName , mbd ));
@@ -842,6 +844,7 @@ class Holder { Class<?> value = null; }
842
844
843
845
// CGLIB subclass methods hide generic parameters; look at the original user class.
844
846
Class <?> fbClass = ClassUtils .getUserClass (beanClass );
847
+
845
848
// Find the given factory method, taking into account that in the case of
846
849
// @Bean methods, there may be parameters present.
847
850
ReflectionUtils .doWithMethods (fbClass ,
@@ -858,6 +861,7 @@ public void doWith(Method method) {
858
861
}
859
862
}
860
863
});
864
+
861
865
return (objectType .value != null && Object .class != objectType .value ? objectType .value : null );
862
866
}
863
867
@@ -908,6 +912,7 @@ private FactoryBean<?> getSingletonFactoryBeanForTypeCheck(String beanName, Root
908
912
(mbd .getFactoryBeanName () != null && isSingletonCurrentlyInCreation (mbd .getFactoryBeanName ()))) {
909
913
return null ;
910
914
}
915
+
911
916
Object instance = null ;
912
917
try {
913
918
// Mark this bean as currently in creation, even if just partially.
@@ -923,6 +928,7 @@ private FactoryBean<?> getSingletonFactoryBeanForTypeCheck(String beanName, Root
923
928
// Finished partial creation of this bean.
924
929
afterSingletonCreation (beanName );
925
930
}
931
+
926
932
FactoryBean <?> fb = getFactoryBean (beanName , instance );
927
933
if (bw != null ) {
928
934
this .factoryBeanInstanceCache .put (beanName , bw );
@@ -943,6 +949,7 @@ private FactoryBean<?> getNonSingletonFactoryBeanForTypeCheck(String beanName, R
943
949
if (isPrototypeCurrentlyInCreation (beanName )) {
944
950
return null ;
945
951
}
952
+
946
953
Object instance = null ;
947
954
try {
948
955
// Mark this bean as currently in creation, even if just partially.
@@ -966,6 +973,7 @@ private FactoryBean<?> getNonSingletonFactoryBeanForTypeCheck(String beanName, R
966
973
// Finished partial creation of this bean.
967
974
afterPrototypeCreation (beanName );
968
975
}
976
+
969
977
return getFactoryBean (beanName , instance );
970
978
}
971
979
0 commit comments