29
29
import java .util .HashSet ;
30
30
import java .util .LinkedHashMap ;
31
31
import java .util .LinkedHashSet ;
32
- import java .util .LinkedList ;
33
32
import java .util .List ;
34
33
import java .util .Map ;
35
34
import java .util .Set ;
36
35
import java .util .concurrent .ConcurrentHashMap ;
36
+ import java .util .concurrent .CopyOnWriteArrayList ;
37
37
38
38
import org .springframework .beans .BeanUtils ;
39
39
import org .springframework .beans .BeanWrapper ;
@@ -145,16 +145,16 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
145
145
private TypeConverter typeConverter ;
146
146
147
147
/** String resolvers to apply e.g. to annotation attribute values */
148
- private final List <StringValueResolver > embeddedValueResolvers = new LinkedList <>();
148
+ private final List <StringValueResolver > embeddedValueResolvers = new CopyOnWriteArrayList <>();
149
149
150
150
/** BeanPostProcessors to apply in createBean */
151
- private final List <BeanPostProcessor > beanPostProcessors = new ArrayList <>();
151
+ private final List <BeanPostProcessor > beanPostProcessors = new CopyOnWriteArrayList <>();
152
152
153
153
/** Indicates whether any InstantiationAwareBeanPostProcessors have been registered */
154
- private boolean hasInstantiationAwareBeanPostProcessors ;
154
+ private volatile boolean hasInstantiationAwareBeanPostProcessors ;
155
155
156
156
/** Indicates whether any DestructionAwareBeanPostProcessors have been registered */
157
- private boolean hasDestructionAwareBeanPostProcessors ;
157
+ private volatile boolean hasDestructionAwareBeanPostProcessors ;
158
158
159
159
/** Map from scope identifier String to corresponding Scope */
160
160
private final Map <String , Scope > scopes = new LinkedHashMap <>(8 );
@@ -847,14 +847,17 @@ public String resolveEmbeddedValue(@Nullable String value) {
847
847
@ Override
848
848
public void addBeanPostProcessor (BeanPostProcessor beanPostProcessor ) {
849
849
Assert .notNull (beanPostProcessor , "BeanPostProcessor must not be null" );
850
+ // Remove from old position, if any
850
851
this .beanPostProcessors .remove (beanPostProcessor );
851
- this . beanPostProcessors . add ( beanPostProcessor );
852
+ // Track whether it is instantiation/destruction aware
852
853
if (beanPostProcessor instanceof InstantiationAwareBeanPostProcessor ) {
853
854
this .hasInstantiationAwareBeanPostProcessors = true ;
854
855
}
855
856
if (beanPostProcessor instanceof DestructionAwareBeanPostProcessor ) {
856
857
this .hasDestructionAwareBeanPostProcessors = true ;
857
858
}
859
+ // Add to end of list
860
+ this .beanPostProcessors .add (beanPostProcessor );
858
861
}
859
862
860
863
@ Override
@@ -985,7 +988,6 @@ public void copyConfigurationFrom(ConfigurableBeanFactory otherFactory) {
985
988
@ Override
986
989
public BeanDefinition getMergedBeanDefinition (String name ) throws BeansException {
987
990
String beanName = transformedBeanName (name );
988
-
989
991
// Efficiently check whether bean definition exists in this factory.
990
992
if (!containsBeanDefinition (beanName ) && getParentBeanFactory () instanceof ConfigurableBeanFactory ) {
991
993
return ((ConfigurableBeanFactory ) getParentBeanFactory ()).getMergedBeanDefinition (beanName );
@@ -997,18 +999,15 @@ public BeanDefinition getMergedBeanDefinition(String name) throws BeansException
997
999
@ Override
998
1000
public boolean isFactoryBean (String name ) throws NoSuchBeanDefinitionException {
999
1001
String beanName = transformedBeanName (name );
1000
-
1001
1002
Object beanInstance = getSingleton (beanName , false );
1002
1003
if (beanInstance != null ) {
1003
1004
return (beanInstance instanceof FactoryBean );
1004
1005
}
1005
-
1006
1006
// No singleton instance found -> check bean definition.
1007
1007
if (!containsBeanDefinition (beanName ) && getParentBeanFactory () instanceof ConfigurableBeanFactory ) {
1008
1008
// No bean definition found in this factory -> delegate to parent.
1009
1009
return ((ConfigurableBeanFactory ) getParentBeanFactory ()).isFactoryBean (name );
1010
1010
}
1011
-
1012
1011
return isFactoryBean (beanName , getMergedLocalBeanDefinition (beanName ));
1013
1012
}
1014
1013
0 commit comments