gitchenjh opened a new issue #9370: URL: https://github.com/apache/dubbo/issues/9370
<!-- If you need to report a security issue please visit https://github.com/apache/dubbo/security/policy --> see also https://github.com/apache/dubbo/issues/8347 ### Environment * Dubbo version: 2.7.14 * Operating System version: Windows 10 Build: 19044.1387 * Java version: 1.8.0_211 ### Steps to reproduce this issue 1. bootup a spring-boot application with dubbo-spring-boot-starter 2.7.14 2. the application print log like this ``` BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat' of type [org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) ``` Pls. provide [GitHub address] to reproduce this issue. https://github.com/gitchenjh/dubbo-test ### Expected Behavior `DubboConfigEarlyInitializationPostProcessor` shuold only counted as BeanPostProcessor once ### Actual Behavior <!-- What actually happens? --> If there is an exception, please attach the exception trace: `DubboConfigEarlyInitializationPostProcessor` counted as BeanPostProcessor twice #### first time addBeanPostProcessor ```java // org.apache.dubbo.config.spring.beans.factory.config.DubboConfigEarlyInitializationPostProcessor private void initBeanFactory() { if (beanFactory != null) { // Register itself if (logger.isInfoEnabled()) { logger.info("BeanFactory is about to be initialized, trying to resolve the Dubbo Config Beans early " + "initialization"); } beanFactory.addBeanPostProcessor(this); } } ```  #### counted as BeanPostProcessor twice ```java // org.springframework.context.support.PostProcessorRegistrationDelegate public static void registerBeanPostProcessors( ConfigurableListableBeanFactory beanFactory, AbstractApplicationContext applicationContext) { // WARNING: Although it may appear that the body of this method can be easily // refactored to avoid the use of multiple loops and multiple lists, the use // of multiple lists and multiple passes over the names of processors is // intentional. We must ensure that we honor the contracts for PriorityOrdered // and Ordered processors. Specifically, we must NOT cause processors to be // instantiated (via getBean() invocations) or registered in the ApplicationContext // in the wrong order. // // Before submitting a pull request (PR) to change this method, please review the // list of all declined PRs involving changes to PostProcessorRegistrationDelegate // to ensure that your proposal does not result in a breaking change: // https://github.com/spring-projects/spring-framework/issues?q=PostProcessorRegistrationDelegate+is%3Aclosed+label%3A%22status%3A+declined%22 String[] postProcessorNames = beanFactory.getBeanNamesForType(BeanPostProcessor.class, true, false); // 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. int beanProcessorTargetCount = beanFactory.getBeanPostProcessorCount() + 1 + postProcessorNames.length; beanFactory.addBeanPostProcessor(new BeanPostProcessorChecker(beanFactory, beanProcessorTargetCount)); // Separate between BeanPostProcessors that implement PriorityOrdered, // Ordered, and the rest. List<BeanPostProcessor> priorityOrderedPostProcessors = new ArrayList<>(); } ```  `DubboConfigEarlyInitializationPostProcessor` has added as BeanPostProcessor into `DefaultListableBeanFactory`, beanFactory.getBeanPostProcessorCount() has counted once, but beanFactory.getBeanNamesForType() counted it again ```java // org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors // First, register the BeanPostProcessors that implement PriorityOrdered. sortPostProcessors(priorityOrderedPostProcessors, beanFactory); registerBeanPostProcessors(beanFactory, priorityOrderedPostProcessors); //org.springframework.beans.factory.support.AbstractBeanFactory public void addBeanPostProcessors(Collection<? extends BeanPostProcessor> beanPostProcessors) { this.beanPostProcessors.removeAll(beanPostProcessors); this.beanPostProcessors.addAll(beanPostProcessors); } ```  `this.beanPostProcessors.removeAl` will remove `DubboConfigEarlyInitializationPostProcessor` `this.beanPostProcessors.addAll` will add `DubboConfigEarlyInitializationPostProcessor` again so there is only one `DubboConfigEarlyInitializationPostProcessor` instance in `DefaultListableBeanFactory.beanPostProcessors`,but beanProcessorTargetCount counted is twice ```java // org.springframework.context.support.PostProcessorRegistrationDelegate.BeanPostProcessorChecker public Object postProcessAfterInitialization(Object bean, String beanName) { if (!(bean instanceof BeanPostProcessor) && !isInfrastructureBean(beanName) && this.beanFactory.getBeanPostProcessorCount() < this.beanPostProcessorTargetCount) { if (logger.isInfoEnabled()) { logger.info("Bean '" + beanName + "' of type [" + bean.getClass().getName() + "] is not eligible for getting processed by all BeanPostProcessors " + "(for example: not eligible for auto-proxying)"); } } return bean; } ```  The `this.beanFactory.getBeanPostProcessorCount() < this.beanPostProcessorTargetCount` will always be true so after `BeanPostProcessorChecker` added into DefaultListableBeanFactory.beanPostProcessors,during every spring bean initialization, there will print log ``` BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat' of type [org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
