本文介绍了春季指标中的@Timed注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在String Boot rest控制器上使用了 @Timed
批注,并且工作正常.控制器中的方法从服务中调用方法,该方法也用 @Timed
注释.
I use @Timed
annotation on String Boot rest controller and it works fine. Method from controller calls method from service which is also annotated with @Timed
.
但是,此后续Service Bean中方法的注释不起作用(在/metrics
中看不到结果).为什么会这样呢?可以解决吗?
However, this annotation on method in subsequent service bean doesn't work (I don't see results in /metrics
). Why is it happening? Could it be fixed?
推荐答案
根据@Timed在任何Spring管理的bean#361 中,您可以通过注册 TimedAspect
.
As per Support for @Timed in any Spring-managed bean #361 you can get this behaviour by registering TimedAspect
manually.
@Configuration
@EnableAspectJAutoProxy
public class AutoTimingConfiguration {
@Bean
public TimedAspect timedAspect(MeterRegistry registry) {
return new TimedAspect(registry);
}
}
请注意,按照#361中的jkschneider注释:
Do note that as per jkschneider comment in #361:
这篇关于春季指标中的@Timed注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!