Aspect around call on annotated field

I want AspectJ to inject the measuring code around all invocations of any method, on fields annotated with @Measured and capture the method’s name.
This is what I have:

@Pointcut("get(@my.annotation.Measured * *) && @annotation(measured)")
public void fieldAnnotatedWithMeasured(Measured measured) {}

@Around(value = "fieldAnnotatedWithMeasured(measured)", argNames = "joinPoint,measured")
public Object measureField(ProceedingJoinPoint joinPoint, Measured measured) throws Throwable {...}

Use case:

public class A { 

  @Measured private Service service;
  ...
  void call(){
    service.call(); // here I want to measure the call() time and capture its name
  }

This seems to surround only the access to the field, not the method invocation. I want to capture the invoked method name instide the advise.

Source: java

Leave a Reply