fix subscribe service will block admin startup (#779)
diff --git a/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/service/RegistryServerSync.java b/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/service/RegistryServerSync.java
index 6a91f5c..f57cdb3 100644
--- a/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/service/RegistryServerSync.java
+++ b/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/service/RegistryServerSync.java
@@ -27,8 +27,9 @@
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.Registry;
import org.springframework.beans.factory.DisposableBean;
-import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.event.ApplicationReadyEvent;
+import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import java.util.HashMap;
@@ -41,7 +42,7 @@
import java.util.concurrent.atomic.AtomicLong;
@Component
-public class RegistryServerSync implements InitializingBean, DisposableBean, NotifyListener {
+public class RegistryServerSync implements DisposableBean, NotifyListener {
private static final Logger logger = LoggerFactory.getLogger(RegistryServerSync.class);
@@ -76,8 +77,8 @@
return registryCache;
}
- @Override
- public void afterPropertiesSet() throws Exception {
+ @EventListener(classes = ApplicationReadyEvent.class)
+ public void startSubscribe() {
logger.info("Init Dubbo Admin Sync Cache...");
registry.subscribe(SUBSCRIBE, this);
}
diff --git a/dubbo-admin-server/src/test/java/org/apache/dubbo/admin/service/RegistryServerSyncTest.java b/dubbo-admin-server/src/test/java/org/apache/dubbo/admin/service/RegistryServerSyncTest.java
index ad1d631..a8ecc7c 100644
--- a/dubbo-admin-server/src/test/java/org/apache/dubbo/admin/service/RegistryServerSyncTest.java
+++ b/dubbo-admin-server/src/test/java/org/apache/dubbo/admin/service/RegistryServerSyncTest.java
@@ -53,7 +53,7 @@
@Test
public void testAfterPropertiesSet() throws Exception {
- registryServerSync.afterPropertiesSet();
+ registryServerSync.startSubscribe();
verify(registry).subscribe(any(URL.class), any(RegistryServerSync.class));
}