the code in /org/springframework/context/support/PostProcessorRegistrationDelegate.java:82
List<BeanDefinitionRegistryPostProcessor> currentRegistryProcessors = new ArrayList<>();
// First, invoke the BeanDefinitionRegistryPostProcessors that implement PriorityOrdered.
String[] postProcessorNames =
beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class, true, false);
for (String ppName : postProcessorNames) {
if (beanFactory.isTypeMatch(ppName, PriorityOrdered.class)) {
currentRegistryProcessors.add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class));
processedBeans.add(ppName);
}
}
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);
for (String ppName : postProcessorNames) {
if (!processedBeans.contains(ppName) && beanFactory.isTypeMatch(ppName, Ordered.class)) {
currentRegistryProcessors.add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class));
processedBeans.add(ppName);
}
}
sortPostProcessors(currentRegistryProcessors, beanFactory);
registryProcessors.addAll(currentRegistryProcessors);
invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry);
currentRegistryProcessors.clear();
I think can use one For instead of two For.
List<BeanDefinitionRegistryPostProcessor> priorityOrderedRegistryProcessors = new ArrayList<>();
List<BeanDefinitionRegistryPostProcessor> orderedRegistryProcessors = new ArrayList<>();
String[] postProcessorNames =
beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class, true, false);
for (String ppName : postProcessorNames) {
if (beanFactory.isTypeMatch(ppName, PriorityOrdered.class)) {
priorityOrderedRegistryProcessors.add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class));
processedBeans.add(ppName);
} else if (beanFactory.isTypeMatch(ppName, Ordered.class)) {
orderedRegistryProcessors.add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class));
processedBeans.add(ppName);
}
}
// First, invoke the BeanDefinitionRegistryPostProcessors that implement PriorityOrdered.
sortPostProcessors(priorityOrderedRegistryProcessors, beanFactory);
registryProcessors.addAll(priorityOrderedRegistryProcessors);
invokeBeanDefinitionRegistryPostProcessors(priorityOrderedRegistryProcessors, registry);
// Next, invoke the BeanDefinitionRegistryPostProcessors that implement Ordered.
sortPostProcessors(orderedRegistryProcessors, beanFactory);
registryProcessors.addAll(orderedRegistryProcessors);
invokeBeanDefinitionRegistryPostProcessors(orderedRegistryProcessors, registry);
priorityOrderedRegistryProcessors = null;
orderedRegistryProcessors = null;