From bc04bd1433dbe991041028fca944abae5d675874 Mon Sep 17 00:00:00 2001 From: JEECG <445654970@qq.com> Date: Tue, 30 Sep 2025 15:43:24 +0800 Subject: [PATCH] =?UTF-8?q?--author:scott--date:20250930--for:=E4=BD=BF?= =?UTF-8?q?=E7=94=A8@PostConstruct=E6=B3=A8=E8=A7=A3=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96PrometheusMeterRegistry=E9=85=8D=E7=BD=AE=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E5=90=AF=E5=8A=A8=E5=90=8E=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=BB=B6=E8=BF=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/config/WebMvcConfiguration.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java index 67970df0c..49fa352bf 100644 --- a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java +++ b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/WebMvcConfiguration.java @@ -11,22 +11,19 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer; import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; import io.micrometer.prometheusmetrics.PrometheusMeterRegistry; +import jakarta.annotation.PostConstruct; import jakarta.annotation.Resource; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.ObjectProvider; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; -import org.springframework.context.event.EventListener; import org.springframework.http.CacheControl; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; @@ -50,6 +47,7 @@ import java.util.concurrent.TimeUnit; * @Author qinfeng * */ +@Slf4j @Configuration public class WebMvcConfiguration implements WebMvcConfigurer { @@ -157,16 +155,17 @@ public class WebMvcConfiguration implements WebMvcConfigurer { /** - * 监听应用启动完成事件,确保 PrometheusMeterRegistry 已经初始化 + * 在Bean初始化完成后立即配置PrometheusMeterRegistry,避免在Meter注册后才配置MeterFilter * for [QQYUN-12558]【监控】系统监控的头两个tab不好使,接口404 - * @param event * @author chenrui * @date 2025/5/26 16:46 */ - @EventListener - public void onApplicationReady(ApplicationReadyEvent event) { - if(null != meterRegistryPostProcessor){ - meterRegistryPostProcessor.postProcessAfterInitialization(prometheusMeterRegistry, ""); + @PostConstruct + public void initPrometheusMeterRegistry() { + // 确保在应用启动早期就配置MeterFilter,避免警告 + if (null != meterRegistryPostProcessor && null != prometheusMeterRegistry) { + meterRegistryPostProcessor.postProcessAfterInitialization(prometheusMeterRegistry, "prometheusMeterRegistry"); + log.info("PrometheusMeterRegistry配置完成"); } }