finalclassPostProcessorRegistrationDelegate{publicstaticvoidregisterBeanPostProcessors(ConfigurableListableBeanFactorybeanFactory,AbstractApplicationContextapplicationContext){// 从beanDefinitionNames中获取所有BeanPostProcessor类型的beanName。String[]postProcessorNames=beanFactory.getBeanNamesForType(BeanPostProcessor.class,true,false);// 这里之所以要+1,因为在这个方法的结尾处,单独注册了一个BeanPostProcessor:ApplicationListenerDetector// Register BeanPostProcessorChecker that logs an info message when// a bean is created during BeanPostProcessor instantiation, i.e. when// a bean is not eligible for getting processed by all BeanPostProcessors.intbeanProcessorTargetCount=beanFactory.getBeanPostProcessorCount()+1+postProcessorNames.length;beanFactory.addBeanPostProcessor(newBeanPostProcessorChecker(beanFactory,beanProcessorTargetCount));// Separate between BeanPostProcessors that implement PriorityOrdered,// Ordered, and the rest.// 实现了PriorityOrdered接口的。List<BeanPostProcessor>priorityOrderedPostProcessors=newArrayList<>();// MergedBeanDefinitionPostProcessor类型的。List<BeanPostProcessor>internalPostProcessors=newArrayList<>();// 实现了Ordered接口的。List<String>orderedPostProcessorNames=newArrayList<>();// 没有实现排序接口的。List<String>nonOrderedPostProcessorNames=newArrayList<>();// 对以上四种情况进行分别处理。for(StringppName:postProcessorNames){if(beanFactory.isTypeMatch(ppName,PriorityOrdered.class)){BeanPostProcessorpp=beanFactory.getBean(ppName,BeanPostProcessor.class);priorityOrderedPostProcessors.add(pp);if(ppinstanceofMergedBeanDefinitionPostProcessor){internalPostProcessors.add(pp);}}elseif(beanFactory.isTypeMatch(ppName,Ordered.class)){orderedPostProcessorNames.add(ppName);}else{nonOrderedPostProcessorNames.add(ppName);}}// 注册BeanPostProcessors// First, register the BeanPostProcessors that implement PriorityOrdered.sortPostProcessors(priorityOrderedPostProcessors,beanFactory);registerBeanPostProcessors(beanFactory,priorityOrderedPostProcessors);// 注册实现了Ordered接口的BeanPostProcessor。// Next, register the BeanPostProcessors that implement Ordered.List<BeanPostProcessor>orderedPostProcessors=newArrayList<>();for(StringppName:orderedPostProcessorNames){BeanPostProcessorpp=beanFactory.getBean(ppName,BeanPostProcessor.class);orderedPostProcessors.add(pp);if(ppinstanceofMergedBeanDefinitionPostProcessor){internalPostProcessors.add(pp);}}sortPostProcessors(orderedPostProcessors,beanFactory);registerBeanPostProcessors(beanFactory,orderedPostProcessors);// 注册没有实现接口的BeanPostProcessor// Now, register all regular BeanPostProcessors.List<BeanPostProcessor>nonOrderedPostProcessors=newArrayList<>();for(StringppName:nonOrderedPostProcessorNames){BeanPostProcessorpp=beanFactory.getBean(ppName,BeanPostProcessor.class);nonOrderedPostProcessors.add(pp);if(ppinstanceofMergedBeanDefinitionPostProcessor){internalPostProcessors.add(pp);}}registerBeanPostProcessors(beanFactory,nonOrderedPostProcessors);// Finally, re-register all internal BeanPostProcessors.sortPostProcessors(internalPostProcessors,beanFactory);registerBeanPostProcessors(beanFactory,internalPostProcessors);// Re-register post-processor for detecting inner beans as ApplicationListeners,// moving it to the end of the processor chain (for picking up proxies etc).beanFactory.addBeanPostProcessor(newApplicationListenerDetector(applicationContext));}}