简体   繁体   中英

@Timed annotation in spring metrics

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM