@Timed annotation in spring metrics

一世执手 提交于 2021-02-16 13:08:36

问题


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.

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?


回答1:


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);
  }
}

Do note that as per jkschneider comment in #361:

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



来源:https://stackoverflow.com/questions/51749391/timed-annotation-in-spring-metrics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!