Skip to content

Commit dca9574

Browse files
mercyblitzzonghaishang
authored andcommitted
@service and @reference Optimization (#2657)
* Polish #2235 #2251 apache/dubbo-spring-boot-project#243 * Fixed bugs and optimized imports
1 parent 2e826a6 commit dca9574

18 files changed

+691
-696
lines changed

dependencies-bom/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
<jaxb_version>2.2.7</jaxb_version>
113113
<activation_version>1.2.0</activation_version>
114114
<hessian_lite_version>3.2.4</hessian_lite_version>
115+
<alibaba_spring_context_support_version>1.0.1</alibaba_spring_context_support_version>
115116
</properties>
116117

117118
<dependencyManagement>
@@ -358,6 +359,16 @@
358359
<artifactId>hessian-lite</artifactId>
359360
<version>${hessian_lite_version}</version>
360361
</dependency>
362+
363+
<!-- Alibaba extensions -->
364+
365+
<!-- Spring Context Support -->
366+
<dependency>
367+
<groupId>com.alibaba.spring</groupId>
368+
<artifactId>spring-context-support</artifactId>
369+
<version>${alibaba_spring_context_support_version}</version>
370+
</dependency>
371+
361372
<!-- Test lib -->
362373
<dependency>
363374
<groupId>org.apache.curator</groupId>

dubbo-config/dubbo-config-spring/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
-->
17-
<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">
17+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
1819
<modelVersion>4.0.0</modelVersion>
1920
<parent>
2021
<groupId>com.alibaba</groupId>
@@ -51,6 +52,10 @@
5152
<groupId>org.springframework</groupId>
5253
<artifactId>spring-context</artifactId>
5354
</dependency>
55+
<dependency>
56+
<groupId>com.alibaba.spring</groupId>
57+
<artifactId>spring-context-support</artifactId>
58+
</dependency>
5459
<dependency>
5560
<groupId>javax.servlet</groupId>
5661
<artifactId>javax.servlet-api</artifactId>

dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/ServiceBean.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@
2424
import com.alibaba.dubbo.config.RegistryConfig;
2525
import com.alibaba.dubbo.config.ServiceConfig;
2626
import com.alibaba.dubbo.config.annotation.Service;
27+
import com.alibaba.dubbo.config.spring.context.event.ServiceBeanExportedEvent;
2728
import com.alibaba.dubbo.config.spring.extension.SpringExtensionFactory;
29+
2830
import org.springframework.aop.support.AopUtils;
2931
import org.springframework.beans.factory.BeanFactoryUtils;
3032
import org.springframework.beans.factory.BeanNameAware;
3133
import org.springframework.beans.factory.DisposableBean;
3234
import org.springframework.beans.factory.InitializingBean;
3335
import org.springframework.context.ApplicationContext;
3436
import org.springframework.context.ApplicationContextAware;
37+
import org.springframework.context.ApplicationEventPublisher;
38+
import org.springframework.context.ApplicationEventPublisherAware;
3539
import org.springframework.context.ApplicationListener;
3640
import org.springframework.context.event.ContextRefreshedEvent;
3741
import org.springframework.context.support.AbstractApplicationContext;
@@ -46,7 +50,9 @@
4650
*
4751
* @export
4852
*/
49-
public class ServiceBean<T> extends ServiceConfig<T> implements InitializingBean, DisposableBean, ApplicationContextAware, ApplicationListener<ContextRefreshedEvent>, BeanNameAware {
53+
public class ServiceBean<T> extends ServiceConfig<T> implements InitializingBean, DisposableBean,
54+
ApplicationContextAware, ApplicationListener<ContextRefreshedEvent>, BeanNameAware,
55+
ApplicationEventPublisherAware {
5056

5157
private static final long serialVersionUID = 213195494150089726L;
5258

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

6167
private transient boolean supportedApplicationListener;
6268

69+
private ApplicationEventPublisher applicationEventPublisher;
70+
6371
public ServiceBean() {
6472
super();
6573
this.service = null;
@@ -265,6 +273,34 @@ && getInterface() != null && getInterface().length() > 0
265273
}
266274
}
267275

276+
/**
277+
* Get the name of {@link ServiceBean}
278+
*
279+
* @return {@link ServiceBean}'s name
280+
* @since 2.6.5
281+
*/
282+
public String getBeanName() {
283+
return this.beanName;
284+
}
285+
286+
/**
287+
* @since 2.6.5
288+
*/
289+
@Override
290+
public void export() {
291+
super.export();
292+
// Publish ServiceBeanExportedEvent
293+
publishExportEvent();
294+
}
295+
296+
/**
297+
* @since 2.6.5
298+
*/
299+
private void publishExportEvent() {
300+
ServiceBeanExportedEvent exportEvent = new ServiceBeanExportedEvent(this);
301+
applicationEventPublisher.publishEvent(exportEvent);
302+
}
303+
268304
@Override
269305
public void destroy() throws Exception {
270306
// This will only be called for singleton scope bean, and expected to be called by spring shutdown hook when BeanFactory/ApplicationContext destroys.
@@ -280,4 +316,13 @@ protected Class getServiceClass(T ref) {
280316
}
281317
return super.getServiceClass(ref);
282318
}
319+
320+
/**
321+
* @param applicationEventPublisher
322+
* @since 2.6.5
323+
*/
324+
@Override
325+
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
326+
this.applicationEventPublisher = applicationEventPublisher;
327+
}
283328
}

dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/beans/factory/annotation/AbstractAnnotationConfigBeanBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.alibaba.dubbo.config.ModuleConfig;
2222
import com.alibaba.dubbo.config.MonitorConfig;
2323
import com.alibaba.dubbo.config.RegistryConfig;
24+
2425
import org.apache.commons.logging.Log;
2526
import org.apache.commons.logging.LogFactory;
2627
import org.springframework.context.ApplicationContext;
@@ -34,6 +35,7 @@
3435

3536
/**
3637
* Abstract Configurable {@link Annotation} Bean Builder
38+
*
3739
* @since 2.5.7
3840
*/
3941
abstract class AbstractAnnotationConfigBeanBuilder<A extends Annotation, B extends AbstractInterfaceConfig> {
@@ -76,7 +78,7 @@ public final B build() throws Exception {
7678
configureBean(bean);
7779

7880
if (logger.isInfoEnabled()) {
79-
logger.info(bean + " has been built.");
81+
logger.info("The bean[type:" + bean.getClass().getSimpleName() + "] has been built.");
8082
}
8183

8284
return bean;

0 commit comments

Comments
 (0)