|
|
|
@ -22,7 +22,9 @@ import java.security.AccessControlException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.LinkedHashSet; |
|
|
|
import java.util.LinkedHashSet; |
|
|
|
|
|
|
|
import java.util.LinkedList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Locale; |
|
|
|
import java.util.Locale; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
@ -571,22 +573,40 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected void invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory beanFactory) { |
|
|
|
protected void invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory beanFactory) { |
|
|
|
// Invoke BeanDefinitionRegistryPostProcessors first, if any.
|
|
|
|
// Invoke BeanDefinitionRegistryPostProcessors first, if any.
|
|
|
|
|
|
|
|
Set<String> processedBeans = new HashSet<String>(); |
|
|
|
if (beanFactory instanceof BeanDefinitionRegistry) { |
|
|
|
if (beanFactory instanceof BeanDefinitionRegistry) { |
|
|
|
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; |
|
|
|
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; |
|
|
|
Collection<BeanDefinitionRegistryPostProcessor> registryPostProcessors = |
|
|
|
List<BeanFactoryPostProcessor> regularPostProcessors = new LinkedList<BeanFactoryPostProcessor>(); |
|
|
|
beanFactory.getBeansOfType(BeanDefinitionRegistryPostProcessor.class, true, false).values(); |
|
|
|
List<BeanDefinitionRegistryPostProcessor> registryPostProcessors = |
|
|
|
for (BeanDefinitionRegistryPostProcessor postProcessor : registryPostProcessors) { |
|
|
|
new LinkedList<BeanDefinitionRegistryPostProcessor>(); |
|
|
|
postProcessor.postProcessBeanFactory(beanFactory); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (BeanFactoryPostProcessor postProcessor : getBeanFactoryPostProcessors()) { |
|
|
|
for (BeanFactoryPostProcessor postProcessor : getBeanFactoryPostProcessors()) { |
|
|
|
if (postProcessor instanceof BeanDefinitionRegistryPostProcessor) { |
|
|
|
if (postProcessor instanceof BeanDefinitionRegistryPostProcessor) { |
|
|
|
((BeanDefinitionRegistryPostProcessor) postProcessor).postProcessBeanDefinitionRegistry(registry); |
|
|
|
BeanDefinitionRegistryPostProcessor registryPostProcessor = |
|
|
|
|
|
|
|
(BeanDefinitionRegistryPostProcessor) postProcessor; |
|
|
|
|
|
|
|
registryPostProcessor.postProcessBeanDefinitionRegistry(registry); |
|
|
|
|
|
|
|
registryPostProcessors.add(registryPostProcessor); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
regularPostProcessors.add(postProcessor); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, BeanDefinitionRegistryPostProcessor> beanMap = |
|
|
|
|
|
|
|
beanFactory.getBeansOfType(BeanDefinitionRegistryPostProcessor.class, true, false); |
|
|
|
|
|
|
|
List<BeanDefinitionRegistryPostProcessor> registryPostProcessorBeans = |
|
|
|
|
|
|
|
new ArrayList<BeanDefinitionRegistryPostProcessor>(beanMap.values()); |
|
|
|
|
|
|
|
OrderComparator.sort(registryPostProcessorBeans); |
|
|
|
|
|
|
|
for (BeanDefinitionRegistryPostProcessor postProcessor : registryPostProcessorBeans) { |
|
|
|
|
|
|
|
postProcessor.postProcessBeanDefinitionRegistry(registry); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
invokeBeanFactoryPostProcessors(registryPostProcessors, beanFactory); |
|
|
|
|
|
|
|
invokeBeanFactoryPostProcessors(registryPostProcessorBeans, beanFactory); |
|
|
|
|
|
|
|
invokeBeanFactoryPostProcessors(regularPostProcessors, beanFactory); |
|
|
|
|
|
|
|
processedBeans.addAll(beanMap.keySet()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
// Invoke factory processors registered with the context instance.
|
|
|
|
|
|
|
|
invokeBeanFactoryPostProcessors(getBeanFactoryPostProcessors(), beanFactory); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Invoke factory processors registered with the context instance.
|
|
|
|
|
|
|
|
invokeBeanFactoryPostProcessors(getBeanFactoryPostProcessors(), beanFactory); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Do not initialize FactoryBeans here: We need to leave all regular beans
|
|
|
|
// Do not initialize FactoryBeans here: We need to leave all regular beans
|
|
|
|
// uninitialized to let the bean factory post-processors apply to them!
|
|
|
|
// uninitialized to let the bean factory post-processors apply to them!
|
|
|
|
@ -599,7 +619,10 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader |
|
|
|
List<String> orderedPostProcessorNames = new ArrayList<String>(); |
|
|
|
List<String> orderedPostProcessorNames = new ArrayList<String>(); |
|
|
|
List<String> nonOrderedPostProcessorNames = new ArrayList<String>(); |
|
|
|
List<String> nonOrderedPostProcessorNames = new ArrayList<String>(); |
|
|
|
for (String ppName : postProcessorNames) { |
|
|
|
for (String ppName : postProcessorNames) { |
|
|
|
if (isTypeMatch(ppName, PriorityOrdered.class)) { |
|
|
|
if (processedBeans.contains(ppName)) { |
|
|
|
|
|
|
|
// skip - already processed in first phase above
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (isTypeMatch(ppName, PriorityOrdered.class)) { |
|
|
|
priorityOrderedPostProcessors.add(beanFactory.getBean(ppName, BeanFactoryPostProcessor.class)); |
|
|
|
priorityOrderedPostProcessors.add(beanFactory.getBean(ppName, BeanFactoryPostProcessor.class)); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (isTypeMatch(ppName, Ordered.class)) { |
|
|
|
else if (isTypeMatch(ppName, Ordered.class)) { |
|
|
|
@ -634,7 +657,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader |
|
|
|
* Invoke the given BeanFactoryPostProcessor beans. |
|
|
|
* Invoke the given BeanFactoryPostProcessor beans. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void invokeBeanFactoryPostProcessors( |
|
|
|
private void invokeBeanFactoryPostProcessors( |
|
|
|
List<BeanFactoryPostProcessor> postProcessors, ConfigurableListableBeanFactory beanFactory) { |
|
|
|
Collection<? extends BeanFactoryPostProcessor> postProcessors, ConfigurableListableBeanFactory beanFactory) { |
|
|
|
|
|
|
|
|
|
|
|
for (BeanFactoryPostProcessor postProcessor : postProcessors) { |
|
|
|
for (BeanFactoryPostProcessor postProcessor : postProcessors) { |
|
|
|
postProcessor.postProcessBeanFactory(beanFactory); |
|
|
|
postProcessor.postProcessBeanFactory(beanFactory); |
|
|
|
@ -996,7 +1019,9 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader |
|
|
|
// Close the state of this context itself.
|
|
|
|
// Close the state of this context itself.
|
|
|
|
closeBeanFactory(); |
|
|
|
closeBeanFactory(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Let subclasses do some final clean-up if they wish...
|
|
|
|
onClose(); |
|
|
|
onClose(); |
|
|
|
|
|
|
|
|
|
|
|
synchronized (this.activeMonitor) { |
|
|
|
synchronized (this.activeMonitor) { |
|
|
|
this.active = false; |
|
|
|
this.active = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|