@@ -145,7 +145,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
145
145
private final List <StringValueResolver > embeddedValueResolvers = new LinkedList <StringValueResolver >();
146
146
147
147
/** BeanPostProcessors to apply in createBean */
148
- private final List <BeanPostProcessor > beanPostProcessors = new ArrayList <BeanPostProcessor >();
148
+ private final List <BeanPostProcessor > beanPostProcessors = Collections . synchronizedList ( new ArrayList <BeanPostProcessor >() );
149
149
150
150
/** Indicates whether any InstantiationAwareBeanPostProcessors have been registered */
151
151
private boolean hasInstantiationAwareBeanPostProcessors ;
@@ -837,10 +837,32 @@ public int getBeanPostProcessorCount() {
837
837
* Return the list of BeanPostProcessors that will get applied
838
838
* to beans created with this factory.
839
839
*/
840
- public List <BeanPostProcessor > getBeanPostProcessors () {
840
+ public List <BeanPostProcessor > getBeanPostProcessorsMutable () {
841
841
return this .beanPostProcessors ;
842
842
}
843
843
844
+ /**
845
+ * Return the list of BeanPostProcessors that will get applied
846
+ * to beans created with this factory.
847
+ */
848
+ public List <BeanPostProcessor > getBeanPostProcessors () {
849
+ synchronized (beanPostProcessors ) {
850
+ return Collections .unmodifiableList (
851
+ new ArrayList <BeanPostProcessor >(this .beanPostProcessors )
852
+ );
853
+ }
854
+ }
855
+
856
+ public <T > void removePostprocessorsOfType (Class <T > type ) {
857
+ synchronized (beanPostProcessors ) {
858
+ for (Iterator <BeanPostProcessor > it = beanPostProcessors .iterator (); it .hasNext (); ) {
859
+ if (type .isAssignableFrom (it .next ().getClass ())) {
860
+ it .remove ();
861
+ }
862
+ }
863
+ }
864
+ }
865
+
844
866
/**
845
867
* Return whether this factory holds a InstantiationAwareBeanPostProcessor
846
868
* that will get applied to singleton beans on shutdown.
@@ -1054,7 +1076,7 @@ public void destroyBean(String beanName, Object beanInstance) {
1054
1076
* @param mbd the merged bean definition
1055
1077
*/
1056
1078
protected void destroyBean (String beanName , Object beanInstance , RootBeanDefinition mbd ) {
1057
- new DisposableBeanAdapter (beanInstance , beanName , mbd , getBeanPostProcessors (), getAccessControlContext ()).destroy ();
1079
+ new DisposableBeanAdapter (beanInstance , beanName , mbd , getBeanPostProcessorsMutable (), getAccessControlContext ()).destroy ();
1058
1080
}
1059
1081
1060
1082
@ Override
@@ -1625,7 +1647,7 @@ public boolean isBeanNameInUse(String beanName) {
1625
1647
protected boolean requiresDestruction (Object bean , RootBeanDefinition mbd ) {
1626
1648
return (bean != null &&
1627
1649
(DisposableBeanAdapter .hasDestroyMethod (bean , mbd ) || (hasDestructionAwareBeanPostProcessors () &&
1628
- DisposableBeanAdapter .hasApplicableProcessors (bean , getBeanPostProcessors ()))));
1650
+ DisposableBeanAdapter .hasApplicableProcessors (bean , getBeanPostProcessorsMutable ()))));
1629
1651
}
1630
1652
1631
1653
/**
@@ -1648,7 +1670,7 @@ protected void registerDisposableBeanIfNecessary(String beanName, Object bean, R
1648
1670
// work for the given bean: DestructionAwareBeanPostProcessors,
1649
1671
// DisposableBean interface, custom destroy method.
1650
1672
registerDisposableBean (beanName ,
1651
- new DisposableBeanAdapter (bean , beanName , mbd , getBeanPostProcessors (), acc ));
1673
+ new DisposableBeanAdapter (bean , beanName , mbd , getBeanPostProcessorsMutable (), acc ));
1652
1674
}
1653
1675
else {
1654
1676
// A bean with a custom scope...
@@ -1657,7 +1679,7 @@ protected void registerDisposableBeanIfNecessary(String beanName, Object bean, R
1657
1679
throw new IllegalStateException ("No Scope registered for scope name '" + mbd .getScope () + "'" );
1658
1680
}
1659
1681
scope .registerDestructionCallback (beanName ,
1660
- new DisposableBeanAdapter (bean , beanName , mbd , getBeanPostProcessors (), acc ));
1682
+ new DisposableBeanAdapter (bean , beanName , mbd , getBeanPostProcessorsMutable (), acc ));
1661
1683
}
1662
1684
}
1663
1685
}
0 commit comments