diff --git a/arex-web-api/src/main/java/com/arextest/web/api/service/WebSpringBootServletInitializer.java b/arex-web-api/src/main/java/com/arextest/web/api/service/WebSpringBootServletInitializer.java index dfec3d76..53ed4b33 100644 --- a/arex-web-api/src/main/java/com/arextest/web/api/service/WebSpringBootServletInitializer.java +++ b/arex-web-api/src/main/java/com/arextest/web/api/service/WebSpringBootServletInitializer.java @@ -1,20 +1,23 @@ package com.arextest.web.api.service; import com.arextest.common.metrics.PrometheusConfiguration; -import javax.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.context.ApplicationListener; import org.springframework.scheduling.annotation.EnableAsync; @Slf4j @EnableAsync // @EnableSchedulerLock(defaultLockAtMostFor = "PT30S") @SpringBootApplication(scanBasePackages = "com.arextest.web") -public class WebSpringBootServletInitializer extends SpringBootServletInitializer { +public class WebSpringBootServletInitializer + extends SpringBootServletInitializer + implements ApplicationListener { @Value("${arex.prometheus.port}") String prometheusPort; @@ -28,8 +31,8 @@ protected SpringApplicationBuilder configure(SpringApplicationBuilder applicatio return application.sources(WebSpringBootServletInitializer.class); } - @PostConstruct - public void init() { + @Override + public void onApplicationEvent(ApplicationReadyEvent event) { PrometheusConfiguration.initMetrics(prometheusPort); } }