kylixs commented on a change in pull request #9397:
URL: https://github.com/apache/dubbo/pull/9397#discussion_r768602564



##########
File path: 
dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/config/DubboConfigEarlyRegistrationPostProcessor.java
##########
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.config.spring.beans.factory.config;
+
+import org.apache.dubbo.config.AbstractConfig;
+import org.apache.dubbo.config.context.ConfigManager;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.config.BeanPostProcessor;
+import 
org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
+import 
org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
+import org.springframework.beans.factory.support.DefaultListableBeanFactory;
+import 
org.springframework.context.annotation.CommonAnnotationBeanPostProcessor;
+import org.springframework.core.PriorityOrdered;
+
+import javax.annotation.PostConstruct;
+
+/**
+ * Generally, {@link AbstractConfig Dubbo Config} Bean will be added into 
{@link ConfigManager} on the bean initialization
+ * life cycle through {@link CommonAnnotationBeanPostProcessor} executing the 
callback of
+ * {@link PostConstruct @PostConstruct}. However, the instantiation and 
initialization of
+ * {@link AbstractConfig Dubbo Config} Bean could be too early before {@link 
CommonAnnotationBeanPostProcessor}, e.g,
+ * execution, thus it's required to register the current instance as a {@link 
BeanPostProcessor} into
+ * {@link DefaultListableBeanFactory the BeanFatory} using {@link 
BeanDefinitionRegistryPostProcessor} as early as
+ * possible.
+ *
+ * @author <a href="mailto:[email protected]";>chenjh</a>
+ * @see DubboConfigEarlyInitializationPostProcessor
+ * @since 2.7.15
+ */
+public class DubboConfigEarlyRegistrationPostProcessor implements 
BeanDefinitionRegistryPostProcessor, PriorityOrdered {
+
+    public static final String BEAN_NAME = 
"dubboConfigEarlyRegistrationPostProcessor";
+
+    private static final Log logger = 
LogFactory.getLog(DubboConfigEarlyRegistrationPostProcessor.class.getName());
+
+    private DefaultListableBeanFactory beanFactory;
+
+    @Override
+    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry 
registry) throws BeansException {
+        this.beanFactory = unwrap(registry);
+        initBeanFactory(beanFactory);
+    }
+
+    @Override
+    public void postProcessBeanFactory(ConfigurableListableBeanFactory 
beanFactory) throws BeansException {
+        if (this.beanFactory == null) { // try again if 
postProcessBeanDefinitionRegistry method does not effect.
+            this.beanFactory = unwrap(beanFactory);
+            initBeanFactory(this.beanFactory);
+        }
+    }
+
+    @Override
+    public int getOrder() {
+        return HIGHEST_PRECEDENCE;
+    }
+
+    private void initBeanFactory(DefaultListableBeanFactory beanFactory) {
+        if (beanFactory != null) {
+            DubboConfigEarlyInitializationPostProcessor dceiPostProcessor =
+                    
DubboConfigEarlyInitializationPostProcessor.getSingleton(beanFactory);
+            // Register itself
+            if (logger.isInfoEnabled()) {
+                logger.info("BeanFactory is about to be initialized, trying to 
resolve the Dubbo Config Beans early " +

Review comment:
       change this log message




-- 
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]

Reply via email to