Skip to content

Commit

Permalink
@service and @reference Optimization (#2657)
Browse files Browse the repository at this point in the history
* Polish #2235 #2251 apache/dubbo-spring-boot-project#243

* Fixed bugs and optimized imports
  • Loading branch information
mercyblitz authored and zonghaishang committed Oct 19, 2018
1 parent 2e826a6 commit dca9574
Show file tree
Hide file tree
Showing 18 changed files with 691 additions and 696 deletions.
11 changes: 11 additions & 0 deletions dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<jaxb_version>2.2.7</jaxb_version>
<activation_version>1.2.0</activation_version>
<hessian_lite_version>3.2.4</hessian_lite_version>
<alibaba_spring_context_support_version>1.0.1</alibaba_spring_context_support_version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -358,6 +359,16 @@
<artifactId>hessian-lite</artifactId>
<version>${hessian_lite_version}</version>
</dependency>

<!-- Alibaba extensions -->

<!-- Spring Context Support -->
<dependency>
<groupId>com.alibaba.spring</groupId>
<artifactId>spring-context-support</artifactId>
<version>${alibaba_spring_context_support_version}</version>
</dependency>

<!-- Test lib -->
<dependency>
<groupId>org.apache.curator</groupId>
Expand Down
7 changes: 6 additions & 1 deletion dubbo-config/dubbo-config-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba</groupId>
Expand Down Expand Up @@ -51,6 +52,10 @@
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.spring</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.dubbo.config.spring.context.event.ServiceBeanExportedEvent;
import com.alibaba.dubbo.config.spring.extension.SpringExtensionFactory;

import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.support.AbstractApplicationContext;
Expand All @@ -46,7 +50,9 @@
*
* @export
*/
public class ServiceBean<T> extends ServiceConfig<T> implements InitializingBean, DisposableBean, ApplicationContextAware, ApplicationListener<ContextRefreshedEvent>, BeanNameAware {
public class ServiceBean<T> extends ServiceConfig<T> implements InitializingBean, DisposableBean,
ApplicationContextAware, ApplicationListener<ContextRefreshedEvent>, BeanNameAware,
ApplicationEventPublisherAware {

private static final long serialVersionUID = 213195494150089726L;

Expand All @@ -60,6 +66,8 @@ public class ServiceBean<T> extends ServiceConfig<T> implements InitializingBean

private transient boolean supportedApplicationListener;

private ApplicationEventPublisher applicationEventPublisher;

public ServiceBean() {
super();
this.service = null;
Expand Down Expand Up @@ -265,6 +273,34 @@ && getInterface() != null && getInterface().length() > 0
}
}

/**
* Get the name of {@link ServiceBean}
*
* @return {@link ServiceBean}'s name
* @since 2.6.5
*/
public String getBeanName() {
return this.beanName;
}

/**
* @since 2.6.5
*/
@Override
public void export() {
super.export();
// Publish ServiceBeanExportedEvent
publishExportEvent();
}

/**
* @since 2.6.5
*/
private void publishExportEvent() {
ServiceBeanExportedEvent exportEvent = new ServiceBeanExportedEvent(this);
applicationEventPublisher.publishEvent(exportEvent);
}

@Override
public void destroy() throws Exception {
// This will only be called for singleton scope bean, and expected to be called by spring shutdown hook when BeanFactory/ApplicationContext destroys.
Expand All @@ -280,4 +316,13 @@ protected Class getServiceClass(T ref) {
}
return super.getServiceClass(ref);
}

/**
* @param applicationEventPublisher
* @since 2.6.5
*/
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.applicationEventPublisher = applicationEventPublisher;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.alibaba.dubbo.config.ModuleConfig;
import com.alibaba.dubbo.config.MonitorConfig;
import com.alibaba.dubbo.config.RegistryConfig;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
Expand All @@ -34,6 +35,7 @@

/**
* Abstract Configurable {@link Annotation} Bean Builder
*
* @since 2.5.7
*/
abstract class AbstractAnnotationConfigBeanBuilder<A extends Annotation, B extends AbstractInterfaceConfig> {
Expand Down Expand Up @@ -76,7 +78,7 @@ public final B build() throws Exception {
configureBean(bean);

if (logger.isInfoEnabled()) {
logger.info(bean + " has been built.");
logger.info("The bean[type:" + bean.getClass().getSimpleName() + "] has been built.");
}

return bean;
Expand Down
Loading

0 comments on commit dca9574

Please sign in to comment.