|
|
|
|
@ -58,15 +58,14 @@ class PostProcessorRegistrationDelegate {
@@ -58,15 +58,14 @@ class PostProcessorRegistrationDelegate {
|
|
|
|
|
if (beanFactory instanceof BeanDefinitionRegistry) { |
|
|
|
|
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; |
|
|
|
|
List<BeanFactoryPostProcessor> regularPostProcessors = new LinkedList<BeanFactoryPostProcessor>(); |
|
|
|
|
List<BeanDefinitionRegistryPostProcessor> registryPostProcessors = |
|
|
|
|
new LinkedList<BeanDefinitionRegistryPostProcessor>(); |
|
|
|
|
List<BeanDefinitionRegistryPostProcessor> registryProcessors = new LinkedList<BeanDefinitionRegistryPostProcessor>(); |
|
|
|
|
|
|
|
|
|
for (BeanFactoryPostProcessor postProcessor : beanFactoryPostProcessors) { |
|
|
|
|
if (postProcessor instanceof BeanDefinitionRegistryPostProcessor) { |
|
|
|
|
BeanDefinitionRegistryPostProcessor registryPostProcessor = |
|
|
|
|
BeanDefinitionRegistryPostProcessor registryProcessor = |
|
|
|
|
(BeanDefinitionRegistryPostProcessor) postProcessor; |
|
|
|
|
registryPostProcessor.postProcessBeanDefinitionRegistry(registry); |
|
|
|
|
registryPostProcessors.add(registryPostProcessor); |
|
|
|
|
registryProcessor.postProcessBeanDefinitionRegistry(registry); |
|
|
|
|
registryProcessors.add(registryProcessor); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
regularPostProcessors.add(postProcessor); |
|
|
|
|
@ -77,33 +76,34 @@ class PostProcessorRegistrationDelegate {
@@ -77,33 +76,34 @@ class PostProcessorRegistrationDelegate {
|
|
|
|
|
// uninitialized to let the bean factory post-processors apply to them!
|
|
|
|
|
// Separate between BeanDefinitionRegistryPostProcessors that implement
|
|
|
|
|
// PriorityOrdered, Ordered, and the rest.
|
|
|
|
|
String[] postProcessorNames = |
|
|
|
|
beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class, true, false); |
|
|
|
|
List<BeanDefinitionRegistryPostProcessor> currentRegistryProcessors = new ArrayList<BeanDefinitionRegistryPostProcessor>(); |
|
|
|
|
|
|
|
|
|
// First, invoke the BeanDefinitionRegistryPostProcessors that implement PriorityOrdered.
|
|
|
|
|
List<BeanDefinitionRegistryPostProcessor> priorityOrderedPostProcessors = new ArrayList<BeanDefinitionRegistryPostProcessor>(); |
|
|
|
|
String[] postProcessorNames = |
|
|
|
|
beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class, true, false); |
|
|
|
|
for (String ppName : postProcessorNames) { |
|
|
|
|
if (beanFactory.isTypeMatch(ppName, PriorityOrdered.class)) { |
|
|
|
|
priorityOrderedPostProcessors.add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class)); |
|
|
|
|
currentRegistryProcessors.add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class)); |
|
|
|
|
processedBeans.add(ppName); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
sortPostProcessors(beanFactory, priorityOrderedPostProcessors); |
|
|
|
|
registryPostProcessors.addAll(priorityOrderedPostProcessors); |
|
|
|
|
invokeBeanDefinitionRegistryPostProcessors(priorityOrderedPostProcessors, registry); |
|
|
|
|
sortPostProcessors(currentRegistryProcessors, beanFactory); |
|
|
|
|
registryProcessors.addAll(currentRegistryProcessors); |
|
|
|
|
invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry); |
|
|
|
|
currentRegistryProcessors.clear(); |
|
|
|
|
|
|
|
|
|
// Next, invoke the BeanDefinitionRegistryPostProcessors that implement Ordered.
|
|
|
|
|
postProcessorNames = beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class, true, false); |
|
|
|
|
List<BeanDefinitionRegistryPostProcessor> orderedPostProcessors = new ArrayList<BeanDefinitionRegistryPostProcessor>(); |
|
|
|
|
for (String ppName : postProcessorNames) { |
|
|
|
|
if (!processedBeans.contains(ppName) && beanFactory.isTypeMatch(ppName, Ordered.class)) { |
|
|
|
|
orderedPostProcessors.add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class)); |
|
|
|
|
currentRegistryProcessors.add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class)); |
|
|
|
|
processedBeans.add(ppName); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
sortPostProcessors(beanFactory, orderedPostProcessors); |
|
|
|
|
registryPostProcessors.addAll(orderedPostProcessors); |
|
|
|
|
invokeBeanDefinitionRegistryPostProcessors(orderedPostProcessors, registry); |
|
|
|
|
sortPostProcessors(currentRegistryProcessors, beanFactory); |
|
|
|
|
registryProcessors.addAll(currentRegistryProcessors); |
|
|
|
|
invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry); |
|
|
|
|
currentRegistryProcessors.clear(); |
|
|
|
|
|
|
|
|
|
// Finally, invoke all other BeanDefinitionRegistryPostProcessors until no further ones appear.
|
|
|
|
|
boolean reiterate = true; |
|
|
|
|
@ -112,17 +112,19 @@ class PostProcessorRegistrationDelegate {
@@ -112,17 +112,19 @@ class PostProcessorRegistrationDelegate {
|
|
|
|
|
postProcessorNames = beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class, true, false); |
|
|
|
|
for (String ppName : postProcessorNames) { |
|
|
|
|
if (!processedBeans.contains(ppName)) { |
|
|
|
|
BeanDefinitionRegistryPostProcessor pp = beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class); |
|
|
|
|
registryPostProcessors.add(pp); |
|
|
|
|
currentRegistryProcessors.add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class)); |
|
|
|
|
processedBeans.add(ppName); |
|
|
|
|
pp.postProcessBeanDefinitionRegistry(registry); |
|
|
|
|
reiterate = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
sortPostProcessors(currentRegistryProcessors, beanFactory); |
|
|
|
|
registryProcessors.addAll(currentRegistryProcessors); |
|
|
|
|
invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry); |
|
|
|
|
currentRegistryProcessors.clear(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Now, invoke the postProcessBeanFactory callback of all processors handled so far.
|
|
|
|
|
invokeBeanFactoryPostProcessors(registryPostProcessors, beanFactory); |
|
|
|
|
invokeBeanFactoryPostProcessors(registryProcessors, beanFactory); |
|
|
|
|
invokeBeanFactoryPostProcessors(regularPostProcessors, beanFactory); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -157,7 +159,7 @@ class PostProcessorRegistrationDelegate {
@@ -157,7 +159,7 @@ class PostProcessorRegistrationDelegate {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// First, invoke the BeanFactoryPostProcessors that implement PriorityOrdered.
|
|
|
|
|
sortPostProcessors(beanFactory, priorityOrderedPostProcessors); |
|
|
|
|
sortPostProcessors(priorityOrderedPostProcessors, beanFactory); |
|
|
|
|
invokeBeanFactoryPostProcessors(priorityOrderedPostProcessors, beanFactory); |
|
|
|
|
|
|
|
|
|
// Next, invoke the BeanFactoryPostProcessors that implement Ordered.
|
|
|
|
|
@ -165,7 +167,7 @@ class PostProcessorRegistrationDelegate {
@@ -165,7 +167,7 @@ class PostProcessorRegistrationDelegate {
|
|
|
|
|
for (String postProcessorName : orderedPostProcessorNames) { |
|
|
|
|
orderedPostProcessors.add(beanFactory.getBean(postProcessorName, BeanFactoryPostProcessor.class)); |
|
|
|
|
} |
|
|
|
|
sortPostProcessors(beanFactory, orderedPostProcessors); |
|
|
|
|
sortPostProcessors(orderedPostProcessors, beanFactory); |
|
|
|
|
invokeBeanFactoryPostProcessors(orderedPostProcessors, beanFactory); |
|
|
|
|
|
|
|
|
|
// Finally, invoke all other BeanFactoryPostProcessors.
|
|
|
|
|
@ -214,7 +216,7 @@ class PostProcessorRegistrationDelegate {
@@ -214,7 +216,7 @@ class PostProcessorRegistrationDelegate {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// First, register the BeanPostProcessors that implement PriorityOrdered.
|
|
|
|
|
sortPostProcessors(beanFactory, priorityOrderedPostProcessors); |
|
|
|
|
sortPostProcessors(priorityOrderedPostProcessors, beanFactory); |
|
|
|
|
registerBeanPostProcessors(beanFactory, priorityOrderedPostProcessors); |
|
|
|
|
|
|
|
|
|
// Next, register the BeanPostProcessors that implement Ordered.
|
|
|
|
|
@ -226,7 +228,7 @@ class PostProcessorRegistrationDelegate {
@@ -226,7 +228,7 @@ class PostProcessorRegistrationDelegate {
|
|
|
|
|
internalPostProcessors.add(pp); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
sortPostProcessors(beanFactory, orderedPostProcessors); |
|
|
|
|
sortPostProcessors(orderedPostProcessors, beanFactory); |
|
|
|
|
registerBeanPostProcessors(beanFactory, orderedPostProcessors); |
|
|
|
|
|
|
|
|
|
// Now, register all regular BeanPostProcessors.
|
|
|
|
|
@ -241,7 +243,7 @@ class PostProcessorRegistrationDelegate {
@@ -241,7 +243,7 @@ class PostProcessorRegistrationDelegate {
|
|
|
|
|
registerBeanPostProcessors(beanFactory, nonOrderedPostProcessors); |
|
|
|
|
|
|
|
|
|
// Finally, re-register all internal BeanPostProcessors.
|
|
|
|
|
sortPostProcessors(beanFactory, internalPostProcessors); |
|
|
|
|
sortPostProcessors(internalPostProcessors, beanFactory); |
|
|
|
|
registerBeanPostProcessors(beanFactory, internalPostProcessors); |
|
|
|
|
|
|
|
|
|
// Re-register post-processor for detecting inner beans as ApplicationListeners,
|
|
|
|
|
@ -249,7 +251,7 @@ class PostProcessorRegistrationDelegate {
@@ -249,7 +251,7 @@ class PostProcessorRegistrationDelegate {
|
|
|
|
|
beanFactory.addBeanPostProcessor(new ApplicationListenerDetector(applicationContext)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static void sortPostProcessors(ConfigurableListableBeanFactory beanFactory, List<?> postProcessors) { |
|
|
|
|
private static void sortPostProcessors(List<?> postProcessors, ConfigurableListableBeanFactory beanFactory) { |
|
|
|
|
Comparator<Object> comparatorToUse = null; |
|
|
|
|
if (beanFactory instanceof DefaultListableBeanFactory) { |
|
|
|
|
comparatorToUse = ((DefaultListableBeanFactory) beanFactory).getDependencyComparator(); |
|
|
|
|
|