SpringBoot 应用程序监控 添加定时注释会导致错误



我正在将千分尺实现到Spring Web项目。尝试添加@Timed注释时。在添加@Timed之前,我应该创建TimedSpect bean。但它说无法自动连接找不到 MeterRegistry 类型的 bean

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

不确定您是否仍然需要这个答案,但这是我尝试过的并且工作正常。

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

确保你的pom中有以下的入门依赖。

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

最新更新