SpringBoot application monitoring Adding Timed annotation cause to error

655 Views Asked by At

I'm implementing micrometer to spring web project. While trying to add @Timed annotation. Prior to add @Timed i'm supposed to create TimedSpect bean. But it says could not autowire no bean of MeterRegistry type found

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

There are 1 best solutions below

0
Indra Uprade On

Not sure if you still need this answer but this is what i tried and its working fine.

@Configuration
@EnableAspectJAutoProxy
public class TimedConfiguration {

  @Autowired
  MeterRegistry registry;

  @Bean
  public TimedAspect timedAspect(MeterRegistry registry) {
    return new TimedAspect(registry);
  }
}

Make sure you have below starter dependency in your pom.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aop</artifactId>
</dependency>