Skip to content

Commit

Permalink
Polish apache#4910 : [Feature] To suppoort DubboLifecycleComponentApp…
Browse files Browse the repository at this point in the history
…licationListener in Spring XML scenario
  • Loading branch information
mercyblitz committed Aug 21, 2019
1 parent 9c46d74 commit 492bc64
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @see SmartApplicationListener
* @since 2.7.4
*/
public class DubboLifecycleComponentsApplicationListener implements ApplicationListener {
public class DubboLifecycleComponentApplicationListener implements ApplicationListener {

private List<Lifecycle> lifecycleComponents = emptyList();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.DubboLifecycleComponentApplicationListener;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

import static org.apache.dubbo.config.spring.util.AnnotatedBeanDefinitionRegistryUtils.registerBeans;

/**
* A {@link ImportBeanDefinitionRegistrar register} for the {@link Lifecycle Dubbo Lifecycle} components
*
* @since 2.7.4
*/
public class DubboLifecycleComponentRegistrar implements ImportBeanDefinitionRegistrar {

@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
registerBeans(registry, DubboLifecycleComponentApplicationListener.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package org.apache.dubbo.config.spring.context.annotation;

import org.apache.dubbo.config.spring.context.DubboLifecycleComponentsApplicationListener;

import org.springframework.context.Lifecycle;
import org.springframework.context.annotation.Import;

Expand All @@ -37,6 +35,6 @@
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@Import(DubboLifecycleComponentsApplicationListener.class)
@Import(DubboLifecycleComponentRegistrar.class)
public @interface EnableDubboLifecycle {
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
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.DubboLifecycleComponentApplicationListener;
import org.apache.dubbo.config.spring.util.AnnotatedBeanDefinitionRegistryUtils;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
Expand All @@ -38,6 +40,8 @@
import org.springframework.context.annotation.AnnotationConfigUtils;
import org.w3c.dom.Element;

import static org.apache.dubbo.config.spring.util.AnnotatedBeanDefinitionRegistryUtils.registerBeans;

/**
* DubboNamespaceHandler
*
Expand Down Expand Up @@ -76,18 +80,34 @@ public void init() {
*/
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
registerAnnotationConfigProcessors(parserContext);
BeanDefinitionRegistry registry = parserContext.getRegistry();
registerAnnotationConfigProcessors(registry);
registerDubboLifecycleComponentApplicationListener(registry);
BeanDefinition beanDefinition = super.parse(element, parserContext);
setSource(beanDefinition);
return beanDefinition;
}

/**
* @param parserContext {@link ParserContext}
* Register {@link DubboLifecycleComponentApplicationListener} as a Spring Bean
*
* @param registry {@link BeanDefinitionRegistry}
* @see DubboLifecycleComponentApplicationListener
* @see AnnotatedBeanDefinitionRegistryUtils#registerBeans(BeanDefinitionRegistry, Class[])
* @since 2.7.4
*/
private void registerAnnotationConfigProcessors(ParserContext parserContext) {
BeanDefinitionRegistry registry = parserContext.getRegistry();
private void registerDubboLifecycleComponentApplicationListener(BeanDefinitionRegistry registry) {
registerBeans(registry, DubboLifecycleComponentApplicationListener.class);
}

/**
* Register the processors for the Spring Annotation-Driven features
*
* @param registry {@link BeanDefinitionRegistry}
* @see AnnotationConfigUtils
* @since 2.7.4
*/
private void registerAnnotationConfigProcessors(BeanDefinitionRegistry registry) {
AnnotationConfigUtils.registerAnnotationConfigProcessors(registry);
}
}

0 comments on commit 492bc64

Please sign in to comment.