我正在使用AOP编写自定义指标服务。这是我的custon注解
@Retention(RUNTIME)
@Target(METHOD)
public @interface Metric {
}
和方面类:
@RequiredArgsConstructor
@Aspect
@Component
@Data
public class MetricAspect {
Map<Signature, Map<Object, Counter>> metrics = new HashMap<>();
@AfterReturning("@annotation(Metric)")
public void afterReturning(JoinPoint joinPoint) {
Signature signature = joinPoint.getSignature();
metrics.get(signature).get("Success").increment();
}
}
我在方法上添加了自定义注释:
@Override
@Metric
public GetCMOwnerInvoiceResponseDTO getCMOwnerInvoice(GetCMOwnerInvoiceRequestDTO getCMOwnerInvoiceRequest) throws ValidationWebFault_Exception {
GetCMOwnerInvoiceRequest request = wsConversionService.convert(getCMOwnerInvoiceRequest, GetCMOwnerInvoiceRequest.class);
GetCMOwnerInvoiceResponse response = invoiceService.getCMOwnerInvoice(request);
return wsConversionService.convert(response, GetCMOwnerInvoiceResponseDTO.class);
}
我需要将方法
GetCMOwnerInvoiceResponseDTO
对象的结果添加到我的metrics
映射中,而不是单词“ Success”。我需要使用哪些参数或注释? 最佳答案
您可以使用returning
属性
@AfterReturning("@annotation(Metric)" , returning="returnValue")
public void afterReturning(JoinPoint joinPoint, Object returnValue) {