From 01b5a03324a4845246b47f1a3d624b2e5e306f7a Mon Sep 17 00:00:00 2001 From: hongqiaowei Date: Fri, 4 Mar 2022 16:59:46 +0800 Subject: [PATCH] Set serviceName in gateway heartbeat --- .../main/java/we/config/FizzGatewayNodeStatSchedConfig.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fizz-core/src/main/java/we/config/FizzGatewayNodeStatSchedConfig.java b/fizz-core/src/main/java/we/config/FizzGatewayNodeStatSchedConfig.java index 8d28fa9..f994e9f 100644 --- a/fizz-core/src/main/java/we/config/FizzGatewayNodeStatSchedConfig.java +++ b/fizz-core/src/main/java/we/config/FizzGatewayNodeStatSchedConfig.java @@ -21,6 +21,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext; import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.data.redis.core.ReactiveStringRedisTemplate; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; @@ -63,9 +64,10 @@ public class FizzGatewayNodeStatSchedConfig extends SchedConfig { @PostConstruct public void postConstruct() { - stat.serviceName = applicationContext.getApplicationName(); + ConfigurableEnvironment env = applicationContext.getEnvironment(); + stat.serviceName = env.getProperty("spring.application.name"); stat.ip = NetworkUtils.getServerIp(); - stat.port = Integer.parseInt(applicationContext.getEnvironment().getProperty("server.port", "8600")); + stat.port = Integer.parseInt(env.getProperty("server.port", "8600")); hashKey = stat.ip + ':' + stat.port; stat.startTs = ManagementFactory.getRuntimeMXBean().getStartTime(); }