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 );
@@ -850,14 +850,17 @@ public String resolveEmbeddedValue(@Nullable String value) {
850
850
@ Override
851
851
public void addBeanPostProcessor (BeanPostProcessor beanPostProcessor ) {
852
852
Assert .notNull (beanPostProcessor , "BeanPostProcessor must not be null" );
853
+ // Remove from old position, if any
853
854
this .beanPostProcessors .remove (beanPostProcessor );
854
- this . beanPostProcessors . add ( beanPostProcessor );
855
+ // Track whether it is instantiation/destruction aware
855
856
if (beanPostProcessor instanceof InstantiationAwareBeanPostProcessor ) {
856
857
this .hasInstantiationAwareBeanPostProcessors = true ;
857
858
}
858
859
if (beanPostProcessor instanceof DestructionAwareBeanPostProcessor ) {
859
860
this .hasDestructionAwareBeanPostProcessors = true ;
860
861
}
862
+ // Add to end of list
863
+ this .beanPostProcessors .add (beanPostProcessor );
861
864
}
862
865
863
866
@ Override
@@ -988,7 +991,6 @@ public void copyConfigurationFrom(ConfigurableBeanFactory otherFactory) {
988
991
@ Override
989
992
public BeanDefinition getMergedBeanDefinition (String name ) throws BeansException {
990
993
String beanName = transformedBeanName (name );
991
-
992
994
// Efficiently check whether bean definition exists in this factory.
993
995
if (!containsBeanDefinition (beanName ) && getParentBeanFactory () instanceof ConfigurableBeanFactory ) {
994
996
return ((ConfigurableBeanFactory ) getParentBeanFactory ()).getMergedBeanDefinition (beanName );
@@ -1000,18 +1002,15 @@ public BeanDefinition getMergedBeanDefinition(String name) throws BeansException
1000
1002
@ Override
1001
1003
public boolean isFactoryBean (String name ) throws NoSuchBeanDefinitionException {
1002
1004
String beanName = transformedBeanName (name );
1003
-
1004
1005
Object beanInstance = getSingleton (beanName , false );
1005
1006
if (beanInstance != null ) {
1006
1007
return (beanInstance instanceof FactoryBean );
1007
1008
}
1008
-
1009
1009
// No singleton instance found -> check bean definition.
1010
1010
if (!containsBeanDefinition (beanName ) && getParentBeanFactory () instanceof ConfigurableBeanFactory ) {
1011
1011
// No bean definition found in this factory -> delegate to parent.
1012
1012
return ((ConfigurableBeanFactory ) getParentBeanFactory ()).isFactoryBean (name );
1013
1013
}
1014
-
1015
1014
return isFactoryBean (beanName , getMergedLocalBeanDefinition (beanName ));
1016
1015
}
1017
1016
0 commit comments