You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

自定义@TimedExtended注解失效,指标无法上报Influx求助

解决自定义@TimedExtended注解不生效的问题

Micrometer默认只会识别原生的@Timed注解,你的自定义注解作为元注解使用时,不会被自动扫描处理,需要显式配置让Micrometer识别它,下面两种方法任选其一:

方法一:自定义TimedAspect Bean

创建配置类,手动指定TimedAspect要处理的注解类型(包含原生@Timed和你的TimedExtended):

import io.micrometer.core.annotation.Timed;
import io.micrometer.core.aop.TimedAspect;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MicrometerConfig {

    @Bean
    public TimedAspect timedAspect(MeterRegistry meterRegistry) {
        return new TimedAspect(meterRegistry, Timed.class, TimedExtended.class);
    }
}

方法二:通过配置属性指定额外注解(Spring Boot 2.4+适用)

在application.properties中添加配置:

management.metrics.annotations.timed.extra-annotation-types=你的包路径.TimedExtended

或者application.yml:

management:
  metrics:
    annotations:
      timed:
        extra-annotation-types: 你的包路径.TimedExtended

注意事项

  • 替换配置中的你的包路径为TimedExtended注解实际所在的包名
  • 确保自定义注解的RetentionPolicy为RUNTIME(你已经正确配置)

内容的提问来源于stack exchange,提问作者евгений кунцевич

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 09:47:19