You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/07/08 14:13:36 UTC
[dubbo] branch 3.0 updated: Remove DubboLifecycleComponent (#8232)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 02a366c Remove DubboLifecycleComponent (#8232)
02a366c is described below
commit 02a366c64fd0642cef513c9451a94934122357e2
Author: Gong Dewei <ky...@qq.com>
AuthorDate: Thu Jul 8 22:13:23 2021 +0800
Remove DubboLifecycleComponent (#8232)
---
...DubboLifecycleComponentApplicationListener.java | 99 ----------------------
.../DubboLifecycleComponentRegistrar.java | 43 ----------
.../context/annotation/EnableDubboLifecycle.java | 42 ---------
.../dubbo/config/spring/util/DubboBeanUtils.java | 6 --
.../boot/autoconfigure/DubboAutoConfiguration.java | 7 +-
5 files changed, 1 insertion(+), 196 deletions(-)
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
deleted file mode 100644
index 4fce372..0000000
--- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboLifecycleComponentApplicationListener.java
+++ /dev/null
@@ -1,99 +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.context;
-
-
-import org.apache.dubbo.common.context.Lifecycle;
-
-import com.alibaba.spring.context.OnceApplicationContextEventListener;
-import org.springframework.context.ApplicationContext;
-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.LinkedList;
-import java.util.List;
-
-import static java.util.Collections.emptyList;
-import static org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors;
-
-/**
- * A {@link ApplicationListener listener} for the {@link Lifecycle Dubbo Lifecycle} components
- *
- * @see {@link Lifecycle Dubbo Lifecycle}
- * @see SmartApplicationListener
- * @since 2.7.5
- * @deprecated Binding the life cycle of Dubbo components with spring is not a good way. Now control components life cycle in DubboBootstrap.
- */
-@Deprecated
-public class DubboLifecycleComponentApplicationListener extends OnceApplicationContextEventListener {
-
- /**
- * The bean name of {@link DubboLifecycleComponentApplicationListener}
- *
- * @since 2.7.6
- */
- public static final String BEAN_NAME = "dubboLifecycleComponentApplicationListener";
-
- private List<Lifecycle> lifecycleComponents = emptyList();
-
- public DubboLifecycleComponentApplicationListener() {
- }
-
- public DubboLifecycleComponentApplicationListener(ApplicationContext applicationContext) {
- super(applicationContext);
- }
-
- @Override
- protected void onApplicationContextEvent(ApplicationContextEvent event) {
- if (event instanceof ContextRefreshedEvent) {
- onContextRefreshedEvent((ContextRefreshedEvent) event);
- } else if (event instanceof ContextClosedEvent) {
- onContextClosedEvent((ContextClosedEvent) event);
- }
- }
-
- protected void onContextRefreshedEvent(ContextRefreshedEvent event) {
- initLifecycleComponents(event);
- startLifecycleComponents();
- }
-
- protected void onContextClosedEvent(ContextClosedEvent event) {
- destroyLifecycleComponents();
- }
-
- private void initLifecycleComponents(ContextRefreshedEvent event) {
- ApplicationContext context = event.getApplicationContext();
- lifecycleComponents = new LinkedList<>();
- // load the Beans of Lifecycle from ApplicationContext
- loadLifecycleComponents(lifecycleComponents, context);
- }
-
- private void loadLifecycleComponents(List<Lifecycle> lifecycleComponents, ApplicationContext context) {
- lifecycleComponents.addAll(beansOfTypeIncludingAncestors(context, Lifecycle.class).values());
- }
-
- private void startLifecycleComponents() {
- lifecycleComponents.forEach(Lifecycle::start);
- }
-
- private void destroyLifecycleComponents() {
- lifecycleComponents.forEach(Lifecycle::destroy);
- }
-}
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
deleted file mode 100644
index 3d6acd0..0000000
--- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/annotation/DubboLifecycleComponentRegistrar.java
+++ /dev/null
@@ -1,43 +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.context.annotation;
-
-import org.apache.dubbo.common.context.Lifecycle;
-import org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener;
-
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
-import org.springframework.core.type.AnnotationMetadata;
-
-import static com.alibaba.spring.util.AnnotatedBeanDefinitionRegistryUtils.registerBeans;
-
-/**
- * A {@link ImportBeanDefinitionRegistrar register} for the {@link Lifecycle Dubbo Lifecycle} components
- *
- * @since 2.7.5
- * @deprecated as 2.7.6, Dubbo {@link Lifecycle} components will be registered automatically. Current class may be
- * removed in the future
- */
-@Deprecated
-public class DubboLifecycleComponentRegistrar implements ImportBeanDefinitionRegistrar {
-
- @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/main/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboLifecycle.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboLifecycle.java
deleted file mode 100644
index f97c1c5..0000000
--- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/annotation/EnableDubboLifecycle.java
+++ /dev/null
@@ -1,42 +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.context.annotation;
-
-import org.apache.dubbo.common.context.Lifecycle;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Enables Dubbo {@link Lifecycle} components
- *
- * @since 2.7.5
- * @deprecated as 2.7.6, Dubbo {@link Lifecycle} components will be registered automatically. Current annotation may be
- * removed in the future
- */
-@Target({ElementType.TYPE})
-@Retention(RetentionPolicy.RUNTIME)
-@Inherited
-@Documented
-//@Import(DubboLifecycleComponentRegistrar.class) // Disabled since 2.7.6
-@Deprecated
-public @interface EnableDubboLifecycle {
-}
diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/DubboBeanUtils.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/DubboBeanUtils.java
index b5a1a0c..61765e8 100644
--- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/DubboBeanUtils.java
+++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/DubboBeanUtils.java
@@ -26,7 +26,6 @@ import org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotati
import org.apache.dubbo.config.spring.beans.factory.config.DubboConfigDefaultPropertyValueBeanPostProcessor;
import org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener;
import org.apache.dubbo.config.spring.context.DubboInfraBeanRegisterPostProcessor;
-import org.apache.dubbo.config.spring.context.DubboLifecycleComponentApplicationListener;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
@@ -56,7 +55,6 @@ public interface DubboBeanUtils {
* @see ReferenceAnnotationBeanPostProcessor
* @see DubboConfigDefaultPropertyValueBeanPostProcessor
* @see DubboConfigAliasPostProcessor
- * @see DubboLifecycleComponentApplicationListener
* @see DubboBootstrapApplicationListener
*/
static void registerCommonBeans(BeanDefinitionRegistry registry) {
@@ -74,10 +72,6 @@ public interface DubboBeanUtils {
registerInfrastructureBean(registry, DubboConfigAliasPostProcessor.BEAN_NAME,
DubboConfigAliasPostProcessor.class);
- // Since 2.7.5 Register DubboLifecycleComponentApplicationListener as an infrastructure Bean
-// registerInfrastructureBean(registry, DubboLifecycleComponentApplicationListener.BEAN_NAME,
-// DubboLifecycleComponentApplicationListener.class);
-
// Since 2.7.4 Register DubboBootstrapApplicationListener as an infrastructure Bean
registerInfrastructureBean(registry, DubboBootstrapApplicationListener.BEAN_NAME,
DubboBootstrapApplicationListener.class);
diff --git a/dubbo-spring-boot/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboAutoConfiguration.java b/dubbo-spring-boot/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboAutoConfiguration.java
index 51be6ac..40e1299 100644
--- a/dubbo-spring-boot/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboAutoConfiguration.java
+++ b/dubbo-spring-boot/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboAutoConfiguration.java
@@ -21,7 +21,6 @@ import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor;
import org.apache.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationPostProcessor;
import org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener;
-import org.apache.dubbo.config.spring.context.DubboLifecycleComponentApplicationListener;
import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig;
import org.springframework.beans.BeansException;
@@ -80,11 +79,8 @@ public class DubboAutoConfiguration implements ApplicationContextAware, BeanDefi
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
if (applicationContext instanceof ConfigurableApplicationContext) {
ConfigurableApplicationContext context = (ConfigurableApplicationContext) applicationContext;
-// DubboLifecycleComponentApplicationListener dubboLifecycleComponentApplicationListener
-// = new DubboLifecycleComponentApplicationListener();
-// dubboLifecycleComponentApplicationListener.setApplicationContext(applicationContext);
-// context.addApplicationListener(dubboLifecycleComponentApplicationListener);
+ // Why register ApplicationListener here?
DubboBootstrapApplicationListener dubboBootstrapApplicationListener = new DubboBootstrapApplicationListener();
dubboBootstrapApplicationListener.setApplicationContext(applicationContext);
context.addApplicationListener(dubboBootstrapApplicationListener);
@@ -95,7 +91,6 @@ public class DubboAutoConfiguration implements ApplicationContextAware, BeanDefi
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
// Remove the BeanDefinitions of ApplicationListener from DubboBeanUtils#registerCommonBeans(BeanDefinitionRegistry)
// TODO Refactoring in Dubbo 2.7.9
- removeBeanDefinition(registry, DubboLifecycleComponentApplicationListener.BEAN_NAME);
removeBeanDefinition(registry, DubboBootstrapApplicationListener.BEAN_NAME);
}