diff --git a/linkis-commons/linkis-rpc/pom.xml b/linkis-commons/linkis-rpc/pom.xml
index 70ef8e6bc7..9447c6f554 100644
--- a/linkis-commons/linkis-rpc/pom.xml
+++ b/linkis-commons/linkis-rpc/pom.xml
@@ -40,8 +40,17 @@
org.springframework.cloud
spring-cloud-commons
+
+ org.springframework.cloud
+ spring-cloud-loadbalancer
+
+
+ org.springframework.cloud
+ spring-cloud-loadbalancer
+ ${spring-netflix.version}
+
org.springframework.cloud
spring-cloud-starter-openfeign
diff --git a/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/conf/EurekaClientCacheManualRefresher.java b/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/conf/EurekaClientCacheManualRefresher.java
index 48d0a0dc45..2fad4432ea 100644
--- a/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/conf/EurekaClientCacheManualRefresher.java
+++ b/linkis-commons/linkis-rpc/src/main/java/org/apache/linkis/rpc/conf/EurekaClientCacheManualRefresher.java
@@ -25,14 +25,13 @@
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
-import com.netflix.discovery.DiscoveryClient;
-import com.netflix.discovery.TimedSupervisorTask;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,7 +42,7 @@ public class EurekaClientCacheManualRefresher {
private final AtomicBoolean isRefreshing = new AtomicBoolean(false);
private final ExecutorService refreshExecutor = Executors.newSingleThreadExecutor();
private final String cacheRefreshTaskField = "cacheRefreshTask";
- private TimedSupervisorTask cacheRefreshTask;
+ private Object cacheRefreshTask;
private long lastRefreshMillis = 0;
private final Duration refreshIntervalDuration = Duration.ofSeconds(3);
@@ -75,14 +74,15 @@ public void refresh() {
return;
}
+ String discoveryClientClassName = "com.netflix.discovery.DiscoveryClient";
if (null == cacheRefreshTask) {
+ Class> discoveryClientClass = Class.forName(discoveryClientClassName);
Field field =
- ReflectionUtils.findField(DiscoveryClient.class, cacheRefreshTaskField);
+ ReflectionUtils.findField(discoveryClientClass, cacheRefreshTaskField);
if (null != field) {
ReflectionUtils.makeAccessible(field);
- DiscoveryClient discoveryClient = beanFactory.getBean(DiscoveryClient.class);
- cacheRefreshTask =
- (TimedSupervisorTask) ReflectionUtils.getField(field, discoveryClient);
+ Object discoveryClient = beanFactory.getBean(discoveryClientClass);
+ cacheRefreshTask = ReflectionUtils.getField(field, discoveryClient);
}
}
@@ -90,12 +90,16 @@ public void refresh() {
logger.error(
"Field ({}) not found in class '{}'",
cacheRefreshTaskField,
- DiscoveryClient.class.getSimpleName());
+ discoveryClientClassName);
return;
}
lastRefreshMillis = System.currentTimeMillis();
- cacheRefreshTask.run();
+ Class> timedSupervisorTaskClass =
+ Class.forName("com.netflix.discovery.TimedSupervisorTask");
+ Method method = timedSupervisorTaskClass.getDeclaredMethod("run");
+ method.setAccessible(true);
+ method.invoke(cacheRefreshTask);
logger.info(
"Manually refresh eureka client cache completed(DiscoveryClient.cacheRefreshTask#run())");
} catch (Exception e) {