From 40198e9724c938dd608fbbca166b57d7b87038f3 Mon Sep 17 00:00:00 2001 From: "william.liangf" Date: Thu, 22 Mar 2012 04:03:31 +0000 Subject: [PATCH] =?UTF-8?q?DUBBO-294=20=E5=B0=86delay=E7=BC=BA=E7=9C=81?= =?UTF-8?q?=E8=AE=BE=E4=B8=BA-1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@1335 1a56cb94-b969-4eaa-88fa-be21384802f2 --- .../alibaba/dubbo/config/spring/ServiceBean.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/dubbo-config/src/main/java/com/alibaba/dubbo/config/spring/ServiceBean.java b/dubbo-config/src/main/java/com/alibaba/dubbo/config/spring/ServiceBean.java index 3aaf65f16..d797a970b 100644 --- a/dubbo-config/src/main/java/com/alibaba/dubbo/config/spring/ServiceBean.java +++ b/dubbo-config/src/main/java/com/alibaba/dubbo/config/spring/ServiceBean.java @@ -27,6 +27,7 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; +import org.springframework.context.support.AbstractApplicationContext; import com.alibaba.dubbo.config.ApplicationConfig; import com.alibaba.dubbo.config.MonitorConfig; @@ -66,7 +67,18 @@ public class ServiceBean extends ServiceConfig implements InitializingBean Method method = applicationContext.getClass().getMethod("addApplicationListener", new Class[]{ApplicationListener.class}); // 兼容Spring2.0.1 method.invoke(applicationContext, new Object[] {this}); supportedApplicationListener = true; - } catch (Throwable t) { + } catch (Throwable t) { + if (applicationContext instanceof AbstractApplicationContext) { + try { + Method method = AbstractApplicationContext.class.getDeclaredMethod("addListener", new Class[]{ApplicationListener.class}); // 兼容Spring2.0.1 + if (! method.isAccessible()) { + method.setAccessible(true); + } + method.invoke(applicationContext, new Object[] {this}); + supportedApplicationListener = true; + } catch (Throwable t2) { + } + } } } } @@ -92,7 +104,7 @@ public class ServiceBean extends ServiceConfig implements InitializingBean if (delay == null && provider != null) { delay = provider.getDelay(); } - return supportedApplicationListener && delay != null && delay.intValue() == -1; + return supportedApplicationListener && (delay == null || delay.intValue() == -1); } @SuppressWarnings({ "unchecked" }) -- GitLab