Spring source code about PostProcessorRegistrationDelegate?

< H2 > Spring source code about PostProcessorRegistrationDelegate? < / H2 >

Spring4.0 and above about

PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors()
A question of

:

in this method, we can see that it calls the following method several times:

postProcessorNames = beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class, true, false)

even called the method in the loop:

while (reiterate) {
                reiterate = false;
                postProcessorNames = beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class, true, false);
                for (String ppName : postProcessorNames) {
                    if (!processedBeans.contains(ppName)) {
                        currentRegistryProcessors.add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class));
                        processedBeans.add(ppName);
                        reiterate = true;
                    }
                }
                sortPostProcessors(currentRegistryProcessors, beanFactory);
                registryProcessors.addAll(currentRegistryProcessors);
                invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry);
                currentRegistryProcessors.clear();
            }

my guess is that it is possible to call

postProcessor.postProcessBeanDefinitionRegistry(registry);
The

method will lead to changes in the relevant bean definition in beanFactory, so it has been called many times. I don"t know how you understand it. Thank you.

Aug.11,2021

it seems that the logic of this cycle is like this: BeanDefinitionRegistryPostProcessor's postProcessBeanDefinitionRegistry is originally used to operate BeanDefinition, but this is not the reason for the loop here. I am worried about the self-defined postProcessBeanDefinitionRegistry object, and when I execute the invokeBeanDefinitionRegistryPostProcessors method, I register some objects like BeanDefinitionRegistryPostProcessor, which can be done through registry.registerBeanDefinition (), which means something recursive. The above belongs to my opinion. The example of BeanDefinitionRegistryPostProcessor is to carry out additional processing before instantiating bean, which can achieve the effect of transferring flowers and trees.

Menu