1616 */
1717package com .alibaba .dubbo .config .spring ;
1818
19- import com .alibaba .dubbo .config .ApplicationConfig ;
20- import com .alibaba .dubbo .config .ModuleConfig ;
21- import com .alibaba .dubbo .config .MonitorConfig ;
22- import com .alibaba .dubbo .config .ProtocolConfig ;
23- import com .alibaba .dubbo .config .ProviderConfig ;
24- import com .alibaba .dubbo .config .RegistryConfig ;
25- import com .alibaba .dubbo .config .ServiceConfig ;
19+ import com .alibaba .dubbo .config .*;
2620import com .alibaba .dubbo .config .annotation .Service ;
21+ import com .alibaba .dubbo .config .spring .context .event .ServiceBeanExportedEvent ;
2722import com .alibaba .dubbo .config .spring .extension .SpringExtensionFactory ;
2823import org .springframework .aop .support .AopUtils ;
2924import org .springframework .beans .factory .BeanFactoryUtils ;
3025import org .springframework .beans .factory .BeanNameAware ;
3126import org .springframework .beans .factory .DisposableBean ;
3227import org .springframework .beans .factory .InitializingBean ;
33- import org .springframework .context .ApplicationContext ;
34- import org .springframework .context .ApplicationContextAware ;
35- import org .springframework .context .ApplicationListener ;
28+ import org .springframework .context .*;
3629import org .springframework .context .event .ContextRefreshedEvent ;
3730import org .springframework .context .support .AbstractApplicationContext ;
3831
4639 *
4740 * @export
4841 */
49- public class ServiceBean <T > extends ServiceConfig <T > implements InitializingBean , DisposableBean , ApplicationContextAware , ApplicationListener <ContextRefreshedEvent >, BeanNameAware {
42+ public class ServiceBean <T > extends ServiceConfig <T > implements InitializingBean , DisposableBean ,
43+ ApplicationContextAware , ApplicationListener <ContextRefreshedEvent >, BeanNameAware ,
44+ ApplicationEventPublisherAware {
5045
5146 private static final long serialVersionUID = 213195494150089726L ;
5247
@@ -60,6 +55,8 @@ public class ServiceBean<T> extends ServiceConfig<T> implements InitializingBean
6055
6156 private transient boolean supportedApplicationListener ;
6257
58+ private ApplicationEventPublisher applicationEventPublisher ;
59+
6360 public ServiceBean () {
6461 super ();
6562 this .service = null ;
@@ -265,6 +262,34 @@ && getInterface() != null && getInterface().length() > 0
265262 }
266263 }
267264
265+ /**
266+ * Get the name of {@link ServiceBean}
267+ *
268+ * @return {@link ServiceBean}'s name
269+ * @since 2.6.5
270+ */
271+ public String getBeanName () {
272+ return this .beanName ;
273+ }
274+
275+ /**
276+ * @since 2.6.5
277+ */
278+ @ Override
279+ public void export () {
280+ super .export ();
281+ // Publish ServiceBeanExportedEvent
282+ publishExportEvent ();
283+ }
284+
285+ /**
286+ * @since 2.6.5
287+ */
288+ private void publishExportEvent () {
289+ ServiceBeanExportedEvent exportEvent = new ServiceBeanExportedEvent (this );
290+ applicationEventPublisher .publishEvent (exportEvent );
291+ }
292+
268293 @ Override
269294 public void destroy () throws Exception {
270295 // This will only be called for singleton scope bean, and expected to be called by spring shutdown hook when BeanFactory/ApplicationContext destroys.
@@ -280,4 +305,13 @@ protected Class getServiceClass(T ref) {
280305 }
281306 return super .getServiceClass (ref );
282307 }
308+
309+ /**
310+ * @param applicationEventPublisher
311+ * @since 2.6.5
312+ */
313+ @ Override
314+ public void setApplicationEventPublisher (ApplicationEventPublisher applicationEventPublisher ) {
315+ this .applicationEventPublisher = applicationEventPublisher ;
316+ }
283317}
0 commit comments