调用各种beanFactory处理器

默认情况下,通过getBeanFactoryPostProcessors()来获取已经注册的BFPP,两种扩展方式,自定义扩展类实现BeanFactoryPostProcessor接口,可以将自定义类用bean注入进去来实现扩展,也可以在定制化beanFactory方法customizeBeanFactory中调用父类addBeanFactoryPostProcessor方法进行扩展
将已经执行过的BFPP存储在processedBeans中,防止重复执行。
判断beanfactory是否是BeanDefinitionRegistry类型
此处是DefaultListableBeanFactory,实现了BeanDefinitionRegistry接口,所以为true。
BeanDefinitionRegistryPostProcessor是BeanFactoryPostProcessor的子集。
BeanFactoryPostProcessor主要针对的操作对象是BeanFactory,而BeanDefinitionRegistryPostProcessor主要针对的操作对象是BeanDefinition。
存放BeanFactoryPostProcessor的集合regularPostProcessors。
存放BeanDefinitionRegistryPostProcessor的集合registryProcessors。
如果是BeanDefinitionRegistryPostProcessor,直接执行BeanDefinitionRegistryPostProcessor接口中的postProcessBeanDefinitionRegistry方法,并且添加到registryProcessors,用于后续执行postProcessBeanFactory方法。否则,只是普通的BeanFactoryPostProcessor,添加到regularPostProcessors,用于后续执行postProcessBeanFactory方法
currentRegistryProcessors用于保存本次要执行的BeanDefinitionRegistryPostProcessor。
调用所有实现PriorityOrdered接口的BeanDefinitionRegistryPostProcessor实现类
找到所有实现BeanDefinitionRegistryPostProcessor接口bean的beanName。
获取名字对应的bean实例,添加到currentRegistryProcessors中,将要被执行的BFPP名称添加到processedBeans,避免后续重复执行。
按照优先级进行排序操作。添加到registryProcessors中,用于最后执行postProcessBeanFactory方法。
遍历currentRegistryProcessors,执行postProcessBeanDefinitionRegistry方法。
后续步骤与上基本一致。
调用所有实现Ordered接口的BeanDefinitionRegistryPostProcessor实现类
找到所有实现BeanDefinitionRegistryPostProcessor接口bean的beanName,此处需要重复查找的原因在于上面的执行过程中可能会新增其他的BeanDefinitionRegistryPostProcessor。
获取名字对应的bean实例,添加到currentRegistryProcessors中,将要被执行的BFPP名称添加到processedBeans,避免后续重复执行。
按照优先级进行排序操作,添加到registryProcessors中,用于最后执行postProcessBeanFactory方法。遍历currentRegistryProcessors,执行postProcessBeanDefinitionRegistry方法。
顺序是:PriorityOrdered -> Ordered -> 未实现排序接口
最后,调用所有剩下的BeanDefinitionRegistryPostProcessors
找出所有实现BeanDefinitionRegistryPostProcessor接口的类,跳过已经执行过的BeanDefinitionRegistryPostProcessor。获取名字对应的bean实例,添加到currentRegistryProcessors中。将要被执行的BFPP名称添加到processedBeans,避免后续重复执行。添加到registryProcessors中,用于最后执行postProcessBeanFactory方法。遍历currentRegistryProcessors,执行postProcessBeanDefinitionRegistry方法。
调用所有BeanDefinitionRegistryPostProcessor的postProcessBeanFactory方法。最后,调用入参beanFactoryPostProcessors中的普通BeanFactoryPostProcessor的postProcessBeanFactory方法。
如果beanFactory不归属于BeanDefinitionRegistry类型,那么直接执行postProcessBeanFactory方法

到这里为止,入参beanFactoryPostProcessors和容器中的所有BeanDefinitionRegistryPostProcessor已经全部处理完毕。
下面开始处理容器中所有的BeanFactoryPostProcessor
可能会包含一些实现类,只实现了BeanFactoryPostProcessor,并没有实现BeanDefinitionRegistryPostProcessor接口。
找到所有实现BeanFactoryPostProcessor接口的类,用于存放实现了PriorityOrdered接口的BeanFactoryPostProcessor,用于存放实现了Ordered接口的BeanFactoryPostProcessor的beanName,用于存放普通BeanFactoryPostProcessor的beanName。
跳过已经执行过的BeanFactoryPostProcessor。
之后处理这几个集合,执行postProcessBeanFactory方法。
