You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2019/12/19 07:14:32 UTC

[dubbo] branch master updated (b3d74c3 -> 7e4b2f3)

This is an automated email from the ASF dual-hosted git repository.

liujun pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git.


    from b3d74c3  Fix some typos (#5501)
     new 2d2341e  [Dubbo-5495] Services can't be exported for projects driven by annotation but with EnableDubbo/EnableDubboLifecycle not enabled (#5496)
     new 7214308  [Dubbo-5495] The dubbo services can't be exported (#5503)
     new 4848762  coordinate spring and dubbo shutdown hook. (#5504)
     new 7e4b2f3  Fix multi protocol does not work when referencing in ProviderConfig (#5498)

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/dubbo/config/ReferenceConfigBase.java   |  3 +
 .../org/apache/dubbo/config/ServiceConfigBase.java |  6 ++
 .../org/apache/dubbo/config/DubboShutdownHook.java |  6 +-
 .../org/apache/dubbo/config/ServiceConfig.java     |  2 +-
 .../dubbo/config/bootstrap/DubboBootstrap.java     | 10 ++-
 .../ServiceAnnotationBeanPostProcessor.java        | 11 +++-
 .../context/DubboBootstrapApplicationListener.java | 63 +++++++++++++++++++
 ...DubboLifecycleComponentApplicationListener.java | 60 +++++++-----------
 ...meExecutionApplicationContextEventListener.java | 71 ++++++++++++++++++++++
 .../DubboLifecycleComponentRegistrar.java          |  2 +
 .../spring/extension/SpringExtensionFactory.java   | 18 ------
 .../spring/schema/DubboBeanDefinitionParser.java   |  3 +-
 .../spring/schema/DubboNamespaceHandler.java       | 11 ++--
 .../spring/util/ApplicationContextUtils.java       | 60 ------------------
 .../beans/factory/ServiceBeanPostProcessor.java    | 37 -----------
 .../ServiceAnnotationTestConfiguration.java        |  6 --
 .../spring/context/annotation/EnableDubboTest.java |  6 --
 .../annotation/provider/ProviderConfiguration.java |  6 --
 .../spring/util/ApplicationContextUtilsTest.java   | 46 --------------
 19 files changed, 194 insertions(+), 233 deletions(-)
 create mode 100644 dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboBootstrapApplicationListener.java
 create mode 100644 dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/OneTimeExecutionApplicationContextEventListener.java
 delete mode 100644 dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/ApplicationContextUtils.java
 delete mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/ServiceBeanPostProcessor.java
 delete mode 100644 dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/util/ApplicationContextUtilsTest.java


[dubbo] 01/04: [Dubbo-5495] Services can't be exported for projects driven by annotation but with EnableDubbo/EnableDubboLifecycle not enabled (#5496)

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit 2d2341e544927244843fda934529bd8445ea99bf
Author: Mercy Ma <me...@gmail.com>
AuthorDate: Wed Dec 18 10:44:58 2019 +0800

    [Dubbo-5495] Services can't be exported for projects driven by annotation but with EnableDubbo/EnableDubboLifecycle not enabled (#5496)
    
    Fixes #5495
---
 .../ServiceAnnotationBeanPostProcessor.java        | 11 +++-
 .../context/DubboBootstrapApplicationListener.java | 63 +++++++++++++++++++
 ...DubboLifecycleComponentApplicationListener.java | 60 +++++++-----------
 ...meExecutionApplicationContextEventListener.java | 71 ++++++++++++++++++++++
 .../DubboLifecycleComponentRegistrar.java          |  2 +
 .../beans/factory/ServiceBeanPostProcessor.java    | 37 -----------
 .../ServiceAnnotationTestConfiguration.java        |  6 --
 .../spring/context/annotation/EnableDubboTest.java |  6 --
 .../annotation/provider/ProviderConfiguration.java |  6 --
 9 files changed, 167 insertions(+), 95 deletions(-)

diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java
index c96f7b9..08a0965 100644
--- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java
+++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java
@@ -23,6 +23,7 @@ import org.apache.dubbo.config.MethodConfig;
 import org.apache.dubbo.config.annotation.Method;
 import org.apache.dubbo.config.annotation.Service;
 import org.apache.dubbo.config.spring.ServiceBean;
+import org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener;
 import org.apache.dubbo.config.spring.context.annotation.DubboClassPathBeanDefinitionScanner;
 
 import org.springframework.beans.BeansException;
@@ -63,6 +64,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import static com.alibaba.spring.util.AnnotatedBeanDefinitionRegistryUtils.registerBeans;
 import static com.alibaba.spring.util.ObjectUtils.of;
 import static org.apache.dubbo.config.spring.beans.factory.annotation.ServiceBeanNameBuilder.create;
 import static org.apache.dubbo.config.spring.util.DubboAnnotationUtils.resolveServiceInterfaceClass;
@@ -107,6 +109,9 @@ public class ServiceAnnotationBeanPostProcessor implements BeanDefinitionRegistr
     @Override
     public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
 
+        // @since 2.7.5
+        registerBeans(registry, DubboBootstrapApplicationListener.class);
+
         Set<String> resolvedPackagesToScan = resolvePackagesToScan(packagesToScan);
 
         if (!CollectionUtils.isEmpty(resolvedPackagesToScan)) {
@@ -456,10 +461,10 @@ public class ServiceAnnotationBeanPostProcessor implements BeanDefinitionRegistr
     }
 
     private List convertMethodConfigs(Object methodsAnnotation) {
-        if (methodsAnnotation == null){
+        if (methodsAnnotation == null) {
             return Collections.EMPTY_LIST;
         }
-        return MethodConfig.constructMethodConfig((Method[])methodsAnnotation);
+        return MethodConfig.constructMethodConfig((Method[]) methodsAnnotation);
     }
 
     private ManagedList<RuntimeBeanReference> toRuntimeBeanReferences(String... beanNames) {
@@ -523,4 +528,4 @@ public class ServiceAnnotationBeanPostProcessor implements BeanDefinitionRegistr
         this.classLoader = classLoader;
     }
 
-}
+}
\ No newline at end of file
diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboBootstrapApplicationListener.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboBootstrapApplicationListener.java
new file mode 100644
index 0000000..fd11690
--- /dev/null
+++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboBootstrapApplicationListener.java
@@ -0,0 +1,63 @@
+/*
+ * 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.context;
+
+import org.apache.dubbo.config.bootstrap.DubboBootstrap;
+
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ApplicationContextEvent;
+import org.springframework.context.event.ContextClosedEvent;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.core.Ordered;
+
+/**
+ * The {@link ApplicationListener} for {@link DubboBootstrap}'s lifecycle when the {@link ContextRefreshedEvent}
+ * and {@link ContextClosedEvent} raised
+ *
+ * @since 2.7.5
+ */
+public class DubboBootstrapApplicationListener extends OneTimeExecutionApplicationContextEventListener
+        implements Ordered {
+
+    private final DubboBootstrap dubboBootstrap;
+
+    public DubboBootstrapApplicationListener() {
+        this.dubboBootstrap = DubboBootstrap.getInstance();
+    }
+
+    @Override
+    public void onApplicationContextEvent(ApplicationContextEvent event) {
+        if (event instanceof ContextRefreshedEvent) {
+            onContextRefreshedEvent((ContextRefreshedEvent) event);
+        } else if (event instanceof ContextClosedEvent) {
+            onContextClosedEvent((ContextClosedEvent) event);
+        }
+    }
+
+    private void onContextRefreshedEvent(ContextRefreshedEvent event) {
+        dubboBootstrap.start();
+    }
+
+    private void onContextClosedEvent(ContextClosedEvent event) {
+        dubboBootstrap.stop();
+    }
+
+    @Override
+    public int getOrder() {
+        return LOWEST_PRECEDENCE;
+    }
+}
diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboLifecycleComponentApplicationListener.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboLifecycleComponentApplicationListener.java
index 61cb66d..7aad776 100644
--- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboLifecycleComponentApplicationListener.java
+++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboLifecycleComponentApplicationListener.java
@@ -18,20 +18,18 @@ package org.apache.dubbo.config.spring.context;
 
 
 import org.apache.dubbo.common.context.Lifecycle;
-import org.apache.dubbo.common.utils.CollectionUtils;
-import org.apache.dubbo.config.DubboShutdownHook;
-import org.apache.dubbo.config.bootstrap.DubboBootstrap;
 
 import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationEvent;
 import org.springframework.context.ApplicationListener;
 import org.springframework.context.event.ApplicationContextEvent;
 import org.springframework.context.event.ContextClosedEvent;
 import org.springframework.context.event.ContextRefreshedEvent;
 import org.springframework.context.event.SmartApplicationListener;
 
-import java.util.Map;
+import java.util.LinkedList;
+import java.util.List;
 
+import static java.util.Collections.emptyList;
 import static org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors;
 
 /**
@@ -41,15 +39,12 @@ import static org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncl
  * @see SmartApplicationListener
  * @since 2.7.5
  */
-public class DubboLifecycleComponentApplicationListener implements ApplicationListener {
+public class DubboLifecycleComponentApplicationListener extends OneTimeExecutionApplicationContextEventListener {
 
-    @Override
-    public void onApplicationEvent(ApplicationEvent event) {
-
-        if (!supportsEvent(event)) {
-            return;
-        }
+    private List<Lifecycle> lifecycleComponents = emptyList();
 
+    @Override
+    protected void onApplicationContextEvent(ApplicationContextEvent event) {
         if (event instanceof ContextRefreshedEvent) {
             onContextRefreshedEvent((ContextRefreshedEvent) event);
         } else if (event instanceof ContextClosedEvent) {
@@ -58,40 +53,31 @@ public class DubboLifecycleComponentApplicationListener implements ApplicationLi
     }
 
     protected void onContextRefreshedEvent(ContextRefreshedEvent event) {
-        ApplicationContext context = event.getApplicationContext();
-        DubboBootstrap bootstrap = loadBootsttrapAsBean(context);
-        if (bootstrap == null) {
-            bootstrap = DubboBootstrap.getInstance();
-        }
-        bootstrap.start();
+        initLifecycleComponents(event);
+        startLifecycleComponents();
     }
 
     protected void onContextClosedEvent(ContextClosedEvent event) {
-        DubboShutdownHook.getDubboShutdownHook().doDestroy();
+        destroyLifecycleComponents();
     }
 
-    private DubboBootstrap loadBootsttrapAsBean(ApplicationContext context) {
-        Map<String, DubboBootstrap> beans = beansOfTypeIncludingAncestors(context, DubboBootstrap.class);
-        if (CollectionUtils.isNotEmptyMap(beans)) {
-            return beans.values().iterator().next();
-        }
-        return null;
+    private void initLifecycleComponents(ContextRefreshedEvent event) {
+        ApplicationContext context = event.getApplicationContext();
+        ClassLoader classLoader = context.getClassLoader();
+        lifecycleComponents = new LinkedList<>();
+        // load the Beans of Lifecycle from ApplicationContext
+        loadLifecycleComponents(lifecycleComponents, context);
     }
 
-    /**
-     * the specified {@link ApplicationEvent event} must be {@link ApplicationContextEvent} and
-     * its correlative {@link ApplicationContext} must be root
-     *
-     * @param event
-     * @return
-     */
-    private boolean supportsEvent(ApplicationEvent event) {
-        return event instanceof ApplicationContextEvent &&
-                isRootApplicationContext((ApplicationContextEvent) event);
+    private void loadLifecycleComponents(List<Lifecycle> lifecycleComponents, ApplicationContext context) {
+        lifecycleComponents.addAll(beansOfTypeIncludingAncestors(context, Lifecycle.class).values());
     }
 
+    private void startLifecycleComponents() {
+        lifecycleComponents.forEach(Lifecycle::start);
+    }
 
-    private boolean isRootApplicationContext(ApplicationContextEvent event) {
-        return event.getApplicationContext().getParent() == null;
+    private void destroyLifecycleComponents() {
+        lifecycleComponents.forEach(Lifecycle::destroy);
     }
 }
diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/OneTimeExecutionApplicationContextEventListener.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/OneTimeExecutionApplicationContextEventListener.java
new file mode 100644
index 0000000..569a67e
--- /dev/null
+++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/OneTimeExecutionApplicationContextEventListener.java
@@ -0,0 +1,71 @@
+/*
+ * 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.context;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ApplicationContextEvent;
+
+import java.util.Objects;
+
+/**
+ * The abstract class {@link ApplicationListener} for {@link ApplicationContextEvent} guarantees just one-time execution
+ * and prevents the event propagation in the hierarchical {@link ApplicationContext ApplicationContexts}
+ *
+ * @since 2.7.5
+ */
+abstract class OneTimeExecutionApplicationContextEventListener implements ApplicationListener, ApplicationContextAware {
+
+    private ApplicationContext applicationContext;
+
+    public final void onApplicationEvent(ApplicationEvent event) {
+        if (isOriginalEventSource(event) && event instanceof ApplicationContextEvent) {
+            onApplicationContextEvent((ApplicationContextEvent) event);
+        }
+    }
+
+    /**
+     * The subclass overrides this method to handle {@link ApplicationContextEvent}
+     *
+     * @param event {@link ApplicationContextEvent}
+     */
+    protected abstract void onApplicationContextEvent(ApplicationContextEvent event);
+
+    /**
+     * Is original {@link ApplicationContext} as the event source
+     *
+     * @param event {@link ApplicationEvent}
+     * @return
+     */
+    private boolean isOriginalEventSource(ApplicationEvent event) {
+        return (applicationContext == null) // Current ApplicationListener is not a Spring Bean, just was added
+                // into Spring's ConfigurableApplicationContext
+                || Objects.equals(applicationContext, event.getSource());
+    }
+
+    @Override
+    public final void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        this.applicationContext = applicationContext;
+    }
+
+    public ApplicationContext getApplicationContext() {
+        return applicationContext;
+    }
+}
diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/annotation/DubboLifecycleComponentRegistrar.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/annotation/DubboLifecycleComponentRegistrar.java
index c192c8d..20fd1a9 100644
--- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/annotation/DubboLifecycleComponentRegistrar.java
+++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/annotation/DubboLifecycleComponentRegistrar.java
@@ -17,6 +17,7 @@
 package org.apache.dubbo.config.spring.context.annotation;
 
 import org.apache.dubbo.common.context.Lifecycle;
+import org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener;
 import org.apache.dubbo.config.spring.context.DubboLifecycleComponentApplicationListener;
 
 import org.springframework.beans.factory.support.BeanDefinitionRegistry;
@@ -35,5 +36,6 @@ public class DubboLifecycleComponentRegistrar implements ImportBeanDefinitionReg
     @Override
     public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
         registerBeans(registry, DubboLifecycleComponentApplicationListener.class);
+        registerBeans(registry, DubboBootstrapApplicationListener.class);
     }
 }
diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/ServiceBeanPostProcessor.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/ServiceBeanPostProcessor.java
deleted file mode 100644
index 52c7500..0000000
--- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/ServiceBeanPostProcessor.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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;
-
-import org.apache.dubbo.config.spring.ServiceBean;
-
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.config.BeanPostProcessor;
-
-public class ServiceBeanPostProcessor implements BeanPostProcessor {
-    @Override
-    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
-        return bean;
-    }
-
-    @Override
-    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
-        if (bean instanceof ServiceBean) {
-            ((ServiceBean) bean).export();
-        }
-        return bean;
-    }
-}
diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationTestConfiguration.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationTestConfiguration.java
index daa95aa..7a206db 100644
--- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationTestConfiguration.java
+++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationTestConfiguration.java
@@ -21,7 +21,6 @@ import org.apache.dubbo.config.ApplicationConfig;
 import org.apache.dubbo.config.ProtocolConfig;
 import org.apache.dubbo.config.RegistryConfig;
 import org.apache.dubbo.config.annotation.Service;
-import org.apache.dubbo.config.spring.beans.factory.ServiceBeanPostProcessor;
 
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
@@ -86,11 +85,6 @@ public class ServiceAnnotationTestConfiguration {
         return protocolConfig;
     }
 
-    @Bean
-    public ServiceBeanPostProcessor serviceBeanPostProcessor() {
-        return new ServiceBeanPostProcessor();
-    }
-
     @Primary
     @Bean
     public PlatformTransactionManager platformTransactionManager() {
diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboTest.java
index 54660b7..42fadfc 100644
--- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboTest.java
+++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboTest.java
@@ -18,7 +18,6 @@ package org.apache.dubbo.config.spring.context.annotation;
 
 import org.apache.dubbo.config.RegistryConfig;
 import org.apache.dubbo.config.spring.api.DemoService;
-import org.apache.dubbo.config.spring.beans.factory.ServiceBeanPostProcessor;
 import org.apache.dubbo.config.spring.context.annotation.consumer.test.TestConsumerConfiguration;
 import org.apache.dubbo.config.spring.context.annotation.provider.DemoServiceImpl;
 import org.apache.dubbo.rpc.model.ApplicationModel;
@@ -152,11 +151,6 @@ public class EnableDubboTest {
     @EnableTransactionManagement
     public static class TestProviderConfiguration {
 
-        @Bean
-        public ServiceBeanPostProcessor serviceBeanPostProcessor() {
-            return new ServiceBeanPostProcessor();
-        }
-
         @Primary
         @Bean
         public PlatformTransactionManager platformTransactionManager() {
diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/ProviderConfiguration.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/ProviderConfiguration.java
index b31e670..d168af8 100644
--- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/ProviderConfiguration.java
+++ b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/context/annotation/provider/ProviderConfiguration.java
@@ -19,7 +19,6 @@ package org.apache.dubbo.config.spring.context.annotation.provider;
 import org.apache.dubbo.config.ApplicationConfig;
 import org.apache.dubbo.config.ProtocolConfig;
 import org.apache.dubbo.config.RegistryConfig;
-import org.apache.dubbo.config.spring.beans.factory.ServiceBeanPostProcessor;
 import org.apache.dubbo.config.spring.context.annotation.DubboComponentScan;
 
 import org.springframework.context.annotation.Bean;
@@ -82,11 +81,6 @@ public class ProviderConfiguration {
         return protocolConfig;
     }
 
-    @Bean
-    public ServiceBeanPostProcessor serviceBeanPostProcessor() {
-        return new ServiceBeanPostProcessor();
-    }
-
     @Primary
     @Bean
     public PlatformTransactionManager platformTransactionManager() {


[dubbo] 04/04: Fix multi protocol does not work when referencing in ProviderConfig (#5498)

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit 7e4b2f323cd264bc9f282d06b02e03adb49ed606
Author: ken.lj <ke...@gmail.com>
AuthorDate: Wed Dec 18 11:06:03 2019 +0800

    Fix multi protocol does not work when referencing in ProviderConfig (#5498)
    
    fix #5398
---
 .../src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java  | 3 +++
 .../src/main/java/org/apache/dubbo/config/ServiceConfigBase.java    | 6 ++++++
 .../src/main/java/org/apache/dubbo/config/ServiceConfig.java        | 2 +-
 .../dubbo/config/spring/schema/DubboBeanDefinitionParser.java       | 3 ++-
 4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java
index 1eac623..3d52969 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java
@@ -136,6 +136,9 @@ public abstract class ReferenceConfigBase<T> extends AbstractReferenceConfig {
             if (monitor == null) {
                 setMonitor(consumer.getMonitor());
             }
+            if (StringUtils.isEmpty(registryIds)) {
+                setRegistryIds(consumer.getRegistryIds());
+            }
         }
         if (module != null) {
             if (registries == null) {
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java
index 5b0c41f..d7ee88b 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java
@@ -217,6 +217,12 @@ public abstract class ServiceConfigBase<T> extends AbstractServiceConfig {
             if (configCenter == null) {
                 setConfigCenter(provider.getConfigCenter());
             }
+            if (StringUtils.isEmpty(registryIds)) {
+                setRegistryIds(provider.getRegistryIds());
+            }
+            if (StringUtils.isEmpty(protocolIds)) {
+                setProtocolIds(provider.getProtocolIds());
+            }
         }
         if (module != null) {
             if (registries == null) {
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
index 4513437..0a081c5 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
@@ -207,7 +207,7 @@ public class ServiceConfig<T> extends ServiceConfigBase<T> {
     }
 
     private void checkAndUpdateSubConfigs() {
-        // Use default configs defined explicitly on global scope
+        // Use default configs defined explicitly with global scope
         completeCompoundConfigs();
         checkDefault();
         checkProtocol();
diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java
index d2a3e08..9d9280d 100644
--- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java
+++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java
@@ -20,6 +20,7 @@ import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.ReflectUtils;
 import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.config.AbstractServiceConfig;
 import org.apache.dubbo.config.ArgumentConfig;
 import org.apache.dubbo.config.ConsumerConfig;
 import org.apache.dubbo.config.MethodConfig;
@@ -176,7 +177,7 @@ public class DubboBeanDefinitionParser implements BeanDefinitionParser {
                                 RegistryConfig registryConfig = new RegistryConfig();
                                 registryConfig.setAddress(RegistryConfig.NO_AVAILABLE);
                                 beanDefinition.getPropertyValues().addPropertyValue(beanProperty, registryConfig);
-                            } else if ("provider".equals(property) || "registry".equals(property) || ("protocol".equals(property) && ServiceBean.class.equals(beanClass))) {
+                            } else if ("provider".equals(property) || "registry".equals(property) || ("protocol".equals(property) && AbstractServiceConfig.class.isAssignableFrom(beanClass))) {
                                 /**
                                  * For 'provider' 'protocol' 'registry', keep literal value (should be id/name) and set the value to 'registryIds' 'providerIds' protocolIds'
                                  * The following process should make sure each id refers to the corresponding instance, here's how to find the instance for different use cases:


[dubbo] 02/04: [Dubbo-5495] The dubbo services can't be exported (#5503)

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit 7214308b8adfae50c2def5f6f6af37f73d36b9ac
Author: Mercy Ma <me...@gmail.com>
AuthorDate: Wed Dec 18 15:45:50 2019 +0800

    [Dubbo-5495] The dubbo services can't be exported (#5503)
    
    Fixes #5495
---
 .../dubbo/config/spring/schema/DubboNamespaceHandler.java     | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboNamespaceHandler.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboNamespaceHandler.java
index 82a4bd7..924d70a 100644
--- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboNamespaceHandler.java
+++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboNamespaceHandler.java
@@ -31,6 +31,7 @@ import org.apache.dubbo.config.spring.ConfigCenterBean;
 import org.apache.dubbo.config.spring.ReferenceBean;
 import org.apache.dubbo.config.spring.ServiceBean;
 import org.apache.dubbo.config.spring.beans.factory.config.ConfigurableSourceBeanMetadataElement;
+import org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener;
 import org.apache.dubbo.config.spring.context.DubboLifecycleComponentApplicationListener;
 
 import com.alibaba.spring.util.AnnotatedBeanDefinitionRegistryUtils;
@@ -38,6 +39,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
 import org.springframework.beans.factory.support.BeanDefinitionRegistry;
 import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
 import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.context.ApplicationListener;
 import org.springframework.context.annotation.AnnotationConfigUtils;
 import org.w3c.dom.Element;
 
@@ -84,22 +86,23 @@ public class DubboNamespaceHandler extends NamespaceHandlerSupport implements Co
     public BeanDefinition parse(Element element, ParserContext parserContext) {
         BeanDefinitionRegistry registry = parserContext.getRegistry();
         registerAnnotationConfigProcessors(registry);
-        registerDubboLifecycleComponentApplicationListener(registry);
+        registerApplicationListeners(registry);
         BeanDefinition beanDefinition = super.parse(element, parserContext);
         setSource(beanDefinition);
         return beanDefinition;
     }
 
     /**
-     * Register {@link DubboLifecycleComponentApplicationListener} as a Spring Bean
+     * Register {@link ApplicationListener ApplicationListeners} as a Spring Bean
      *
      * @param registry {@link BeanDefinitionRegistry}
-     * @see DubboLifecycleComponentApplicationListener
+     * @see ApplicationListener
      * @see AnnotatedBeanDefinitionRegistryUtils#registerBeans(BeanDefinitionRegistry, Class[])
      * @since 2.7.5
      */
-    private void registerDubboLifecycleComponentApplicationListener(BeanDefinitionRegistry registry) {
+    private void registerApplicationListeners(BeanDefinitionRegistry registry) {
         registerBeans(registry, DubboLifecycleComponentApplicationListener.class);
+        registerBeans(registry, DubboBootstrapApplicationListener.class);
     }
 
     /**


[dubbo] 03/04: coordinate spring and dubbo shutdown hook. (#5504)

Posted by li...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git

commit 4848762b5f821688b27dd076f66d615f5f6a2f40
Author: ken.lj <ke...@gmail.com>
AuthorDate: Wed Dec 18 16:17:21 2019 +0800

    coordinate spring and dubbo shutdown hook. (#5504)
---
 .../org/apache/dubbo/config/DubboShutdownHook.java |  6 +--
 .../dubbo/config/bootstrap/DubboBootstrap.java     | 10 ++--
 .../spring/extension/SpringExtensionFactory.java   | 18 -------
 .../spring/util/ApplicationContextUtils.java       | 60 ----------------------
 .../spring/util/ApplicationContextUtilsTest.java   | 46 -----------------
 5 files changed, 8 insertions(+), 132 deletions(-)

diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java
index 8fc2717..b35b8b9 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java
@@ -25,7 +25,6 @@ import org.apache.dubbo.config.event.DubboShutdownHookRegisteredEvent;
 import org.apache.dubbo.config.event.DubboShutdownHookUnregisteredEvent;
 import org.apache.dubbo.event.Event;
 import org.apache.dubbo.event.EventDispatcher;
-import org.apache.dubbo.registry.support.AbstractRegistryFactory;
 import org.apache.dubbo.rpc.Protocol;
 
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -113,10 +112,7 @@ public class DubboShutdownHook extends Thread {
         if (!destroyed.compareAndSet(false, true)) {
             return;
         }
-        // destroy all the registries
-        AbstractRegistryFactory.destroyAll();
-        // destroy all the protocols
-        destroyProtocols();
+
         // dispatch the DubboDestroyedEvent @since 2.7.5
         dispatch(new DubboServiceDestroyedEvent(this));
     }
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java
index 9594dc5..c7954b5 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java
@@ -155,6 +155,8 @@ public class DubboBootstrap extends GenericEventListener {
 
     private AtomicBoolean started = new AtomicBoolean(false);
 
+    private AtomicBoolean destroyed = new AtomicBoolean(false);
+
     private volatile ServiceInstance serviceInstance;
 
     private volatile MetadataService metadataService;
@@ -181,6 +183,7 @@ public class DubboBootstrap extends GenericEventListener {
         configManager = ApplicationModel.getConfigManager();
         environment = ApplicationModel.getEnvironment();
 
+        DubboShutdownHook.getDubboShutdownHook().register();
         ShutdownHookCallbacks.INSTANCE.addCallback(new ShutdownHookCallback() {
             @Override
             public void callback() throws Throwable {
@@ -189,8 +192,8 @@ public class DubboBootstrap extends GenericEventListener {
         });
     }
 
-    public void registerShutdownHook() {
-        DubboShutdownHook.getDubboShutdownHook().register();
+    public void unRegisterShutdownHook() {
+        DubboShutdownHook.getDubboShutdownHook().unregister();
     }
 
     private boolean isOnlyRegisterProvider() {
@@ -987,7 +990,8 @@ public class DubboBootstrap extends GenericEventListener {
     }
 
     public void destroy() {
-        if (started.compareAndSet(true, false)) {
+        if (started.compareAndSet(true, false)
+                && destroyed.compareAndSet(false, true)) {
             unregisterServiceInstance();
             unexportMetadataService();
             unexportServices();
diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/extension/SpringExtensionFactory.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/extension/SpringExtensionFactory.java
index e0f360e..a35645d 100644
--- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/extension/SpringExtensionFactory.java
+++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/extension/SpringExtensionFactory.java
@@ -21,15 +21,10 @@ import org.apache.dubbo.common.extension.SPI;
 import org.apache.dubbo.common.logger.Logger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.ConcurrentHashSet;
-import org.apache.dubbo.config.DubboShutdownHook;
-import org.apache.dubbo.config.spring.util.ApplicationContextUtils;
 
 import com.alibaba.spring.util.BeanFactoryUtils;
 import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationEvent;
-import org.springframework.context.ApplicationListener;
 import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.context.event.ContextClosedEvent;
 
 import java.util.Set;
 
@@ -40,15 +35,12 @@ public class SpringExtensionFactory implements ExtensionFactory {
     private static final Logger logger = LoggerFactory.getLogger(SpringExtensionFactory.class);
 
     private static final Set<ApplicationContext> CONTEXTS = new ConcurrentHashSet<ApplicationContext>();
-    private static final ApplicationListener SHUTDOWN_HOOK_LISTENER = new ShutdownHookListener();
 
     public static void addApplicationContext(ApplicationContext context) {
         CONTEXTS.add(context);
         if (context instanceof ConfigurableApplicationContext) {
             ((ConfigurableApplicationContext) context).registerShutdownHook();
-            DubboShutdownHook.getDubboShutdownHook().unregister();
         }
-        ApplicationContextUtils.addApplicationListener(context, SHUTDOWN_HOOK_LISTENER);
     }
 
     public static void removeApplicationContext(ApplicationContext context) {
@@ -84,14 +76,4 @@ public class SpringExtensionFactory implements ExtensionFactory {
 
         return null;
     }
-
-    private static class ShutdownHookListener implements ApplicationListener {
-        @Override
-        public void onApplicationEvent(ApplicationEvent event) {
-            if (event instanceof ContextClosedEvent) {
-                DubboShutdownHook shutdownHook = DubboShutdownHook.getDubboShutdownHook();
-                shutdownHook.doDestroy();
-            }
-        }
-    }
 }
diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/ApplicationContextUtils.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/ApplicationContextUtils.java
deleted file mode 100644
index 72d1e1c..0000000
--- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/ApplicationContextUtils.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.util;
-
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.config.ConfigurableBeanFactory;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationListener;
-import org.springframework.context.support.AbstractApplicationContext;
-
-import java.lang.reflect.Method;
-
-/**
- * {@link BeanFactory} Utilities class
- *
- * @see BeanFactory
- * @see ConfigurableBeanFactory
- * @see org.springframework.beans.factory.BeanFactoryUtils
- * @since 2.5.7
- */
-public class ApplicationContextUtils {
-
-    public static boolean addApplicationListener(ApplicationContext applicationContext, ApplicationListener listener) {
-        try {
-            // backward compatibility to spring 2.0.1
-            Method method = applicationContext.getClass().getMethod("addApplicationListener", ApplicationListener.class);
-            method.invoke(applicationContext, listener);
-            return true;
-        } catch (Throwable t) {
-            if (applicationContext instanceof AbstractApplicationContext) {
-                try {
-                    // backward compatibility to spring 2.0.1
-                    Method method = AbstractApplicationContext.class.getDeclaredMethod("addListener", ApplicationListener.class);
-                    if (!method.isAccessible()) {
-                        method.setAccessible(true);
-                    }
-                    method.invoke(applicationContext, listener);
-                    return true;
-                } catch (Throwable t2) {
-                    // ignore
-                }
-            }
-        }
-        return false;
-    }
-}
diff --git a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/util/ApplicationContextUtilsTest.java b/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/util/ApplicationContextUtilsTest.java
deleted file mode 100644
index b7ebb00..0000000
--- a/dubbo-config/dubbo-config-spring/src/test/java/org/apache/dubbo/config/spring/util/ApplicationContextUtilsTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.util;
-
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.GenericApplicationContext;
-
-import static org.apache.dubbo.config.spring.util.ApplicationContextUtils.addApplicationListener;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-/**
- * {@link ApplicationContextUtils} Test
- *
- * @since 2.5.7
- */
-public class ApplicationContextUtilsTest {
-
-    private ApplicationContext applicationContext;
-
-    @BeforeEach
-    public void init() {
-        applicationContext = new GenericApplicationContext();
-    }
-
-    @Test
-    public void testAddApplicationListener() {
-        assertTrue(addApplicationListener(applicationContext, event -> {
-        }));
-    }
-}