gpt4 book ai didi

java - spring 指标中的@Timed 注释

转载 作者:搜寻专家 更新时间:2023-11-01 02:19:33 30 4
gpt4 key购买 nike

我在 String Boot rest Controller 上使用了 @Timed 注释,它工作正常。来自 Controller 的方法调用来自服务的方法,该方法也用 @Timed 注释。

但是,后续服务 bean 中的方法注解不起作用(我没有在 /metrics 中看到结果)。为什么会这样?能修好吗?

最佳答案

根据 Support for @Timed in any Spring-managed bean #361您可以通过注册 TimedAspect 获得此行为手动。

@Configuration
@EnableAspectJAutoProxy
public class AutoTimingConfiguration {
@Bean
public TimedAspect timedAspect(MeterRegistry registry) {
return new TimedAspect(registry);
}
}

请注意,根据 #361 中的 jkschneider 评论:

We can revisit application of @Timed via AOP or a BPP in Boot 2.1, depending on how the community reacts to the feature.

关于java - spring 指标中的@Timed 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51749391/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com